tags:

views:

46

answers:

3

Hi

This is a problem i've tried so solve before but gived up. Basicly i'm using ModalPopupExtenders (from AJAX.NET) to display Panels with a few content (text, controls, etc). And i'm calling it from codebehind. And it works well.

But now i want to replace the ModalPopup with some jQuery dialog box. The problem is calling it from codebehind. As far as i know, i have to register the jQuery libraries on RegisterStartup event, but i've tried it and call the jQuery from codebehind but with no sucess.

Can someone help me? I really want to replace the ModalPopup, they gives me to much trouble.

Thanks in advance.

+1  A: 

You do not actually call jQuery from code behind, you just write some extra javascript code that's run on page load (after the PostBack).

In this start up code you make the jQuery calls.

Aristos
+2  A: 

If you're using a ScriptManager, use RegisterStartupScript(), like this:

ScriptManager.RegisterStartupScript(this, GetType(), "modalscript",
    "$(function() { $('#dialog').dialog(); });", true);

If you're not using a ScriptManager/UpdatePanels, use the equivalent ClientScriptManager version.

It's important to remember to wrap your code in a document.ready handler (IE has the most issues without it), so your elements (in my example, id="dialog") are in the DOM and ready.

Nick Craver
Thank you Nick.When you say to wrap my code in a document.ready, in the sample i've showed bellow i did all from ScriptManager.RegisterStartupScript Is there anything i should change? I've though in write the registerDialog on document.ready, but i don't know if it's the same.
Guilherme Cardoso
@Guilherme - Change the `this` (first argument) to the UpdatePanel you're in if that's the case, also you're not using the `$(function() { });` wrapper in your RegisterStartupScript call, make sure to do this :)
Nick Craver
Thanks again, solved ;)
Guilherme Cardoso
A: 
protected void Page_Load(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this, GetType(), "registerDialog",
        "$(function() { $('#dialog').dialog({autoOpen:false, show:'blind'}); });", true);
}

protected void Button1_Click(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this, GetType(), "openDialog",
        "$('#dialog').dialog('open');", true);
}

Is this the correct way? I've to register it first to stay hidden. Thanksю

Guilherme Cardoso
You should edit the question rather than posting an answer!
abatishchev
Sorry mate, i didn't know it ;)
Guilherme Cardoso