Can't get ScriptManager.RegisterStartupScript in WebControl nested in UpdatePanel to work

前端 未结 10 1287
不思量自难忘°
不思量自难忘° 2020-12-12 17:20

I am having what I believe should be a fairly simple problem, but for the life of me I cannot see my problem. The problem is related to ScriptManager.RegisterStartupScript,

10条回答
  •  天涯浪人
    2020-12-12 18:06

    I had an issue using this in a user control (in a page this worked fine); the Button1 is inside an updatepanel, and the scriptmanager is on the usercontrol.

    protected void Button1_Click(object sender, EventArgs e)  
    {  
        string scriptstring = "alert('Welcome');";  
        ScriptManager.RegisterStartupScript(this, this.GetType(), "alertscript", scriptstring, true);  
    }
    

    Now it seems you have to be careful with the first two arguments, they need to reference your page, not your control

    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "alertscript", scriptstring, true);
    

提交回复
热议问题