How to dynamically not render a script tag?

ispiro

I want to be able to dynamically (on page load) decide to set it to Visible=false so it won't be rendered. I tried runat=server but that's only for virtual paths.

Adil

You can use ClientScriptManager.RegisterClientScriptBlock or ClientScriptManager.RegisterStartupScript to conditionally add the script.

if (condition)
{    
    String csname2 = "ButtonClickScript";
    Type cstype = this.GetType();
    StringBuilder cstext2 = new StringBuilder();
    cstext2.Append("<script type=\"text/javascript\"> function DoClick() {");
    cstext2.Append("Form1.Message.value='Text from client script.'} </");
    cstext2.Append("script>");
    cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false);
}

If you have script that is not small then you can put the script in some js file and use ClientScriptManager.RegisterClientScriptInclude

if (condition)
{
    ClientScriptManager cs = Page.ClientScript;
    cs.RegisterClientScriptInclude("ScriptKey", "ScriptURLToInclude");
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to know that dynamically created script tag was executed?

From Dev

render <script> tag in angularjs

From Dev

Trying to dynamically render JSX tag

From Dev

How do I add the "crossorigin" tag to a dynamically loaded script?

From Dev

How to render html dynamically?

From Dev

Datatables : How to render <a> html tag?

From Dev

Datatables : How to render <a> html tag?

From Dev

In an JavaScript If/else statement, how can I render a script tag based on the condition?

From Dev

Dynamically inserted script tag is not executed in the correct order

From Dev

Setting Script Tag's Attribute Dynamically

From Dev

Dynamically inject script tag pre </body>

From Dev

Dynamically insert script tag that will execute via Reactjs

From Dev

Inserting a <script> tag dynamically via jQuery

From Dev

How to read the values from the dynamically added script tag in head using jquery / javascript

From Dev

How can I dynamically generate javascript within a script tag using jade and express

From Dev

How to dynamically load & render react components?

From Dev

how to render divs dynamically based on the number of items

From Dev

How to render templates dynamically for a static user choice

From Dev

how do I dynamically render title as component

From Dev

How to dynamically render JSX component X times?

From Dev

Pass a value from response.render inside the script tag

From Dev

How to not render the content in the <content> tag in Shadow DOM?

From Dev

How to render <base> tag in wicket framework

From Dev

How to append a div with script tag into an li tag?

From Dev

How to insert a string into a script tag?

From Dev

How to use AngularJS in script tag?

From Dev

Why is jquery sending GET request for a script tag that is dynamically loaded?

From Dev

Load javascript file dynamically by appending script tag to body

From Dev

NetSuite Advanced PDF Dynamically Created in Script - Cannot Set <img> tag

Related Related

  1. 1

    How to know that dynamically created script tag was executed?

  2. 2

    render <script> tag in angularjs

  3. 3

    Trying to dynamically render JSX tag

  4. 4

    How do I add the "crossorigin" tag to a dynamically loaded script?

  5. 5

    How to render html dynamically?

  6. 6

    Datatables : How to render <a> html tag?

  7. 7

    Datatables : How to render <a> html tag?

  8. 8

    In an JavaScript If/else statement, how can I render a script tag based on the condition?

  9. 9

    Dynamically inserted script tag is not executed in the correct order

  10. 10

    Setting Script Tag's Attribute Dynamically

  11. 11

    Dynamically inject script tag pre </body>

  12. 12

    Dynamically insert script tag that will execute via Reactjs

  13. 13

    Inserting a <script> tag dynamically via jQuery

  14. 14

    How to read the values from the dynamically added script tag in head using jquery / javascript

  15. 15

    How can I dynamically generate javascript within a script tag using jade and express

  16. 16

    How to dynamically load & render react components?

  17. 17

    how to render divs dynamically based on the number of items

  18. 18

    How to render templates dynamically for a static user choice

  19. 19

    how do I dynamically render title as component

  20. 20

    How to dynamically render JSX component X times?

  21. 21

    Pass a value from response.render inside the script tag

  22. 22

    How to not render the content in the <content> tag in Shadow DOM?

  23. 23

    How to render <base> tag in wicket framework

  24. 24

    How to append a div with script tag into an li tag?

  25. 25

    How to insert a string into a script tag?

  26. 26

    How to use AngularJS in script tag?

  27. 27

    Why is jquery sending GET request for a script tag that is dynamically loaded?

  28. 28

    Load javascript file dynamically by appending script tag to body

  29. 29

    NetSuite Advanced PDF Dynamically Created in Script - Cannot Set <img> tag

HotTag

Archive