ASP.NET和jQuery - 从codebehind电话 [英] ASP.NET and jQuery - call from codebehind
问题描述
这是我一直如此解决之前,但红粉了问题。
Basicly我使用ModalPopupExtenders(从AJAX.NET),显示有一些内容(文本,控制等)面板。而且我从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.
但现在我想有一些jQuery对话框来代替ModalPopup。这个问题是从codebehind调用它。
据我知道,我必须注册在RegisterStartup事件的jQuery库,但我已经尝试过了,从codebehind但没有sucess调用jQuery的。
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.
有人能帮助我吗?我真的想更换ModalPopup,他们给了我很多麻烦。
Can someone help me? I really want to replace the ModalPopup, they gives me to much trouble.
先谢谢了。
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);
}
这是正确的方法是什么?我已经先注册它留下隐患。
Thanksю
Is this the correct way? I've to register it first to stay hidden. Thanksю
推荐答案
如果你使用一个ScriptManager,使用的 的RegisterStartupScript()
,像这样的:
If you're using a ScriptManager, use RegisterStartupScript()
, like this:
ScriptManager.RegisterStartupScript(this, GetType(), "modalscript",
"$(function() { $('#dialog').dialog(); });", true);
如果你的不的使用一个ScriptManager / UpdatePanel的,使用的相当于 ClientScriptManager
版本。
If you're not using a ScriptManager/UpdatePanels, use the equivalent ClientScriptManager
version.
要记住你的包裹code在的document.ready
处理器(IE浏览器的大多数问题没有它),所以你的元素(在我的例子很重要, ID =对话
)是DOM和准备。
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.
这篇关于ASP.NET和jQuery - 从codebehind电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!