Click here to Skip to main content
15,905,614 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! :)

How can I dynamically insert the java script code into section of .aspx page ? :confused:

Thanks for answer...
Posted

use this.ClientScript.RegisterClientScriptBlock to put a javascript block.

Another way is to use make head as runat="server" and access this from codebehind while the page loads :
HtmlGenericControl thehead = this.FindControl("serverid") as HtmlGenericControl;

thehead.Controls.Add("your block");


Simple. :rose: :)
 
Share this answer
 
ClientScript.RegisterStartupScript(Me.GetType(), "scripts", "<script language='javascript'>" & _
"window.open('" & "URL", 'Window Name', " & _
"'width=650, height=700, resizable=no')" & _
"</script>")


or

button.OnClientClick=" java script Code"
 
Share this answer
 
v2
How about this way?

In .ASPX :
<head>;
    <title>Untitled Page</title>
    <asp:Literal ID="_literal" runat="server"></asp:Literal>
</head>


In .CS :
protected void Page_Load(object sender, EventArgs e)
{
 _literal.Text = "<script language='javascript'>alert('Hello!');</script>";
}


seems to work...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900