How to force execution of value assignment in blocks of type <%=value%>

138 Views Asked by At

is there a directive or a instruction to force the execution of the blocks of type <%=value%> in webpages?, because i have a web project in which i have a block of that type and it just evaluates the very first time (when value is ""), but if i change the value of the variable value, which is a public field of type string, within a button the content doesn't evaluates , i am using value to insert a script. I uploaded a copy of my aspx to my web server and the code works fine, but the problem i have is that it doesn't work while i am debugging, value is never evaluated and the script block is never inserted.

I really need to be able to debug the web application with the script running to keep coding.

Regards.

P.S. I really need to use this method , because the ScriptManager's RegisterClientScriptBlock and RegisterStartupScript for me are useless on previous versions of Internet Explorer.

..........

    public string value = "";

    protected void Button1_Click(object sender, EventArgs e)
    {
        //Just a silly example of a script.
        value = "<script type=\"text/javascript\">alert(Add(3,4));</script" + ">";

    }

.........

<script type="text/javascript">
    function Add(number1, number2) {
        return (number1 + number2);
    }

 </script>

<%=value %>
1

There are 1 best solutions below

3
On

aspx:

<asp:Literal ID="Literal1" runat="server"></asp:Literal>

c#:

Literal1.Text = "<script type=\"text/javascript\">alert(Add(3,4));</script" + ">";

Does that work for you?