ScriptManager.RegisterStartupScript and a Key

0

Good afternoon,

I wanted to understand how this Key works, I have a function in aspx that I need in code-behind, but when I call it with a static Key, putting csname = "x"; It's only called once, but I need to be called as many times as possible I tried to put the name as a variable and it is never called, even without the if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), csname))

Here is the code, this code puts the items in the same row of a gridview, then it checks to see if you put the Expand icon in that row, so that it can be expanded when we click the icon.

protected void gvProduct_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HyperLink hlProcesso = (HyperLink)e.Row.FindControl("hlProcesso");
            GridView gvRepetidos = (GridView)e.Row.FindControl("gvRepetidos");                
            DataTable dtNew = dtFormsFilhos.Clone();
            bool isRepetido = false;                

            foreach (DataRow row in dtFormsFilhos.Rows)
            {
                if (row["ProcessoFilho"].ToString().Contains(hlProcesso.Text))
                {
                    dtNew.Rows.Add(row.ItemArray);
                    isRepetido = true;                          
                }                    
            }

            if (isRepetido)
            {
                //se coloco o csname como "x" ou "inclui", funciona 1x
                //mas se coloco como está, não funciona. Não entendo como essa key funciona!
                string csname = hlProcesso.Text.ToString();
                string cstext = "IncluiExpand('" + hlProcesso.Text + "')";
                if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), csname))
                    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), csname, cstext, true);
            }

            gvRepetidos.DataSource = dtNew;
            gvRepetidos.DataBind();                
        }
    } 
    
asked by anonymous 15.04.2016 / 19:01

1 answer

0

I finally got it!

Instead of ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), csname, cstext, true); , I put this.Controls.Add(new LiteralControl("<script type='text/javascript'>"+csText+";</script>"));

You do not need that if to see if the control already exists, in my case.

    
15.04.2016 / 20:27