开发者

ASP.NET and jQuery - call from codebehind

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 jQ开发者_开发问答uery 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.


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ю


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜