Scriptmanager.Registerstartupscript and Key

Asked

Viewed 43 times

0

Good afternoon,

I wanted to understand how this Key works, I have a function in aspx I need in code-Behind, but when I call with a static Key, putting csname = "x"; She only gets called once, but I need her called as many times as necessary, so I tried to put her name as a variable and she never gets 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 whether it will place the Expand icon on that Row, so that it can be expanded when we click on 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();                
        }
    } 

1 answer

0

Finally got!

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

You don’t even need that if to see if the control already exists, in my case.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.