[英]How to use my CustomControl with javascript inside a gridview inside an update panel?
I got trouble when I want to add my custom control with an gridview and an updatePanel. 当我想使用gridview和updatePanel添加自定义控件时遇到麻烦。 The javascript function is never added to the page even if I write it directly inside the RenderContent method.
即使我直接在RenderContent方法中编写JavaScript函数,也不会将其添加到页面中。
The page is : 该页面是:
UpdatePanel GridView EditItem CustomControl UpdatePanel GridView EditItem CustomControl
" SelectCommand="SELECT * FROM [APP_ROLE]"> “ SelectCommand =” SELECT * FROM [APP_ROLE]“>
The custom constrol looks like that : 自定义constrol看起来像这样:
[ToolboxData("<{0}:TestControl runat=server>")] public class TestControl : WebControl { protected override void OnInit(EventArgs e) { base.OnInit(e); [ToolboxData(“ <{0}:TestControl runat = server>”)]公共类TestControl:WebControl {受保护的重写void OnInit(EventArgs e){base.OnInit(e);
string script = "<SCRIPT type=\"text/javascript\">\n" +
"function show_" + ClientID + "(){alert('toto');}" +
"</SCRIPT>\n";
if (Page.ClientScript.IsClientScriptBlockRegistered("show_" + ClientID))
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "show_" + ClientID, script);
}
protected override void RenderContents(HtmlTextWriter writer)
{
writer.WriteLine("<a href=\"javascript:show_" + ClientID + "();\">click</a>");
}
}
Can anyone help me ? 谁能帮我 ?
Cheers. 干杯。
It looks like your if statement is checking for the existence of the script block, then adding the script block only if it already exists . 好像您的if语句正在检查脚本块是否存在,然后仅在脚本块已经存在时才添加它 。
I'd take out that if statement and see what happens. 我会拿出if语句,看看会发生什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.