RegisterStartupScript doesn't work with ScriptManager,Updatepanel. Why is that?

前端 未结 4 1581
不知归路
不知归路 2020-11-29 03:31
protected void timer1_Tick(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in rpChat.Items)
        {
            TextBox txt = item.FindControl         


        
4条回答
  •  清歌不尽
    2020-11-29 04:09

    You need to user ScriptManager class because you are register script when doing postback and using updatepanel

    MSDN: ScriptManager.RegisterStartupScript

    ScriptManager.RegisterStartupScript method used to add client script to a page when the control is wrapped inside an UpdatePanel.

    ASPX page

    CodeBehind Register StartUp Script

    protected void btnPostback_Click(object sender, EventArgs e)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(@"");
    
        ScriptManager.RegisterStartupScript(btnPostback,this.GetType(), "JSCR", sb.ToString(),false);
    
    }
    

    Detail : Add JavaScript programmatically using RegisterStartupScript during an Asynchronous postback

提交回复
热议问题