Вопрос

I am trying to add JavaScript to a page using ClientScriptManager but the script does not get added to the page. 'trendsTable' contains an asp:Gridview and its display is set to none, but on click of 'RequestReport' I want data bound to the gridview, which dataTabletester does, and then for the display of 'trendsTable' to be set to table.

protected void RequestReport_Click(object sender, EventArgs e)
    {
        //method to bind data to table
        dataTabletester();

        //insert script to make table visible
        String csname1 = "PopupScript";
        Type cstype = this.GetType();

        //Get a Client ScriptManager reference from Page Class

        ClientScriptManager cs = Page.ClientScript;

        if (!cs.IsStartupScriptRegistered(cstype, csname1))
        {
            string script = "function() {document.getElementById('trendsTable').style.display = \"table\";}";


            StringBuilder cstext1 = new StringBuilder();
            cstext1.Append("<script type=text/javascript>");
            cstext1.Append(script);
            cstext1.Append("</script>");

            cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());

        }
    }

Thanks to anyone who can provide any help.

Это было полезно?

Решение

You are defining a function but not calling it. Change:

string script = "function() {document.getElementById('trendsTable').style.display = \"table\";}";

to

string script = "document.getElementById('trendsTable').style.display = \"table\";";
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top