Capture code for a property in Javascript?

I would like to write code in C # for the property in javascript alert (<% = someProperty%>) ;, For some reason, it does not work. Is there a way to burn the codebehind property in javascript? thanks

+4
source share
5 answers

Not sure if this works in your situation, but I think it would be best to attach javascript to the event dynamically in your code behind the page load and just set the parameter value at that point.

For instance:

btnSubmit.Attributes.Add("onclick","alert(" + someProperty + ");"); 
+2
source

I think you are missing the warning "try like this β†’" ('<% = someProperty%>');

+1
source

Perhaps this is a stupid suggestion. You tried

 alert("<%= someProperty%>"); 

?

+1
source

To use ASP.NET expressions <% = =>, your Javascript cannot be in an external .js file . It must be part of the ASPX markup in order to interpret the script.

 <head> <script type="text/javascript"> alert(escape('<%=someProperty%>')); </script> </head> 

Best wishes...

0
source

You can use the ClientScript.RegisterExpandoAttribute method to register the C # code behind the property in the JavaScript property.

0
source

All Articles