How to use <script> tag in code-behind?

H

hb

Hi,

I need to assign javascript code dynamically to this tag in <head> section.
Would you please tell me how to use <script> tag in code behind?

Thank you

hb
 
G

Guest

You can place a asp:literal control in the head section of your page. then
in code you can say:

<head>
<asp:literal id="dynScript" runat="server" />
</head>

CodeBehind:
Sub Page_Load()
dynScript.text = "<script>alert('hello');</script>"
End Sub
 
J

John M Deal

You specifically said you wanted it in the <head> section, however if
you simply want to make the script available to the web page it doesn't
have to go there it can go just about anywhere in the page. If this
will work for you, ASP.Net provides two methods of the page object to
add scripts to the client: RegisterClientScriptBlock and
RegisterStartupScript. Take a look at these and see if they work for
you. If this won't work for you then the literal is the way to go.

Have A Better One!

John M Deal, MCP
Necessity Software
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top