0

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.

1 Answer 1

1

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\";";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.