简体   繁体   English

如何在更新面板的gridview内的JavaScript中使用CustomControl?

[英]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.

相关问题 如何在CustomControl中使用UserControl? - How to Use UserControl Inside CustomControl? 如何从Javascript访问gridview内部的面板? - How to access a panel inside gridview from Javascript? 如何从CustomControl内部找到CustomControl的Parent - How to find the Parent of a CustomControl from inside the CustomControl jQuery在更新面板中过滤gridview的行 - JQuery filter rows of gridview inside an update panel 无法在Update面板中更新Gridview以进行更新 - Cant get Gridview to refresh on update inside Update panel 当按钮执行代码在更新面板之外时,如何使用更新面板内部的更新进度 - How to use update progress inside update panel, when the button executing code is outside update panel 如何将InkToolbar链接到CustomControl内的InkCanvas? - How to link InkToolbar to an InkCanvas which is inside CustomControl? 如何将 HeaderTemplateProperty 应用于 CustomControl 中的 HeaderProperty? - How to apply a HeaderTemplateProperty to a HeaderProperty inside in a CustomControl? 更新面板内的 FileUpload GridView 未在按钮单击时上传文件 - FileUpload GridView inside Update Panel not Uploading Files on Button Click 在更新面板中时,GridView中的按钮单击不触发 - Button click in gridview not firing when inside update panel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM