I got trouble when I want to add my custom control with an gridview and an updatePanel. The javascript function is never added to the page even if I write it directly inside the RenderContent method.
The page is :
UpdatePanel GridView EditItem CustomControl
" SelectCommand="SELECT * FROM [APP_ROLE]">
The custom constrol looks like that :
[ToolboxData("<{0}:TestControl runat=server>")] public class TestControl : WebControl { protected override 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 .
I'd take out that if statement and see what happens.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.