Is it possible to set value of property defined at C# to javascript...
c# Code.
public int v开发者_运维知识库al { get; set; }
Now i want to set val property at java script function
You could do a <% Response.Write( val )%>
, or <%= val %>
in the .aspx page if you wanted something quick and dirty.
Edit If you want to go the reverse. No, it's not really possible. You might look into WebMethods, but that's not directly what you want to do.
Not implicitly.
You can register a startup script with this class.
http://msdn.microsoft.com/en-us/library/stax6fw9.aspx
Are you trying to se a property on a class from javascript or a javascript variable from a C# property? The former isn't possible directly as the C# code isn't available on the client. The latter can be done on the server before the response is sent to the client, but how would depend on whether you are doing web forms or ASP.NET MVC.
Ex: to set javascript value from a C# property using MVC/Razor
<script type="text/javascript">
var jsVariable = '@Model.CSharpProperty';
</script>
It is not possible to do that. asp.net is a serverside technology and javascript is clientside.
I may be wrong but I think the question is about using "Properties" in Javascript like you can do in C# if you want to syntactically hide a method or function with a variable assignment?
If that is the case then yes. You can use "Properties" in Javascript. http://en.wikipedia.org/wiki/Property_(programming)#JavaScript
精彩评论