Page.Controls.Add error
-
i dont understand the error i encounters in my ASPX file below is the syntax: Page.Controls.Add(new LiteralControl("<script language='javascript'> window.alert('my message')</script>")); I used the above syntax and it works fine in my 1st page but when i used it in the other page it gives an error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). somebody who can help me solve this problem..... thanks in advance. :)
xxx
-
i dont understand the error i encounters in my ASPX file below is the syntax: Page.Controls.Add(new LiteralControl("<script language='javascript'> window.alert('my message')</script>")); I used the above syntax and it works fine in my 1st page but when i used it in the other page it gives an error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). somebody who can help me solve this problem..... thanks in advance. :)
xxx
-
The above code is working for me in the page load event. Are you calling the above code in the page load event in both pages.
No, below is the code structure protected void Button1_Click(object sender, EventArgs e) { if(......) { .. .. } else { .. Page.Controls.Add(new LiteralControl("<script language='javascript'> window.alert('My Message')</script>")); } }
xxx
-
No, below is the code structure protected void Button1_Click(object sender, EventArgs e) { if(......) { .. .. } else { .. Page.Controls.Add(new LiteralControl("<script language='javascript'> window.alert('My Message')</script>")); } }
xxx
-
if understood correctly, you are trying to register the javascript to display an alert message at runtime . You can also try like this: Page.ClientScript.RegisterStartupScript(this.GetType(), "testkey", " window.alert('My Message')");
Although you did not have any explanation as to why i encountered such problem, I am still very greetful that you share your knowledge... thanks a lot!!! :thumbsup:I salute :)
xxx