views:

177

answers:

1

Hi,

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.

+1  A: 

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.

ajh1138
Or add a ! in there somewhere.
Joel Etherton