I want to pass data to id
<script language="javascript" src="/foo.aspx?id=1"></script>
I have this code in a aspx page.
The data should be passed on load, before this code is being executed.
how can i do that?
I want to pass data to id
<script language="javascript" src="/foo.aspx?id=1"></script>
I have this code in a aspx page.
The data should be passed on load, before this code is being executed.
how can i do that?
I've gotten more and more averse to putting <% %> in the .aspx file, mostly because you can get into terrible knots trying to escape various kinds of quotes.
Here's another way of doing it:
<asp:Literal id="myscript" runat="server"/>
Then on the server side, when you're handling Page_Load():
int theID = 42;
myscript.Text = string.Format("<script type=\"text/javascript\" " +
" src=\"/foo.aspx?id={0})\"></script>", theID);
Edit: rewritten in C# :)
Page.ClientScript.RegisterClientScriptBlock msdn.microsoft.com/en-us/library/… However, if you need to make code changes in the future to your javascript, you have to recompile your whole codebase, as opposed to making changes in the web form and moving around the <%= %> tag.