c# - Pass value from CodeBehind to Angularjs variable -
I want to assign a value to a value with codebehind with an angle. What is the best way to do this. (Say that I have a variable var userinfo in app.js).
If the page is the default.aspx, then I'll do it for the JS variable in default aspx.cs. ASPX:
& lt; Script & gt; Var idSeparator; & Lt; / Script & gt; Code Back:
Protected Zero Page_load (object sender, event case e) {if (IsPostBack) {} AssignValueToJavascriptVariable (); } Private Wide AssignValueToJavascriptVariable () {string idSeparator = string.Format ("var idSeparator = '{0}';", constant. IDSASARART); If (! Page Classic Script.is Clientblock Lock Registered ("IdSeparator")) {Page.ClientScript.RegisterClientScriptBlock (This. GetType (), "IdSeparator", idSeparator, true); }}
Another approach will be to use properties and with the default .aspx page call Such as
public string idSeparator {return {"receive" {"test"; }} In the ASPX page:
& lt; Script type = "text / javascript" & gt; Var idSeparator = '& lt;% = idSeparator% & gt;'; & Lt; / Script & gt; If you require, you can not only set your property to read and later property values.
Or alternatively you have ASP.NET hidden fields.
Comments
Post a Comment