• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3473
  • Last Modified:

Access Server variable from ASP.NET in javascript

I have a javascript that needs to get the "rootID" value from my asp.net code behind file. The problem is that the link dont write out the id, but it writes out "<%=rootId%>".

It means, this is the link I get:
add.aspx?id=<%=rootId%>

The link should be like this:
add.aspx?id=123

Here is my code:
OnClientClick="try {window.location('add.aspx?id=' + targetEl.id.replace('id','').replace('root_0','<%=rootId%>'));} catch (e) {}"
0
webressurs
Asked:
webressurs
1 Solution
 
Abhi231Commented:
OnClientClick being a server side function will be parsed before being processed by the server, so that the <%=rootId> had been converted to &lt;=rootId&gt;.
We can get the rootId server varialbe to a javascript variable and use the javascript variable in the OnCLientClick.

<script>
var jsRootId = '<%=rootId%>'
</script>

OnClientClick="try {window.location('add.aspx?id=' + targetEl.id.replace('id','').replace('root_0',jsRootId));} catch (e) {}"
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now