asp.net - web.config variable declaration and use in javascript -
how define variable in web.config file , make use of same in javascript code?
i made try assigning key value pair seems not working!
you should pass variable web.config js file via code-behind. example, let's variable named my-variable
. web.config should :
<configuration> <appsettings> <add key="my-variable" value="my-value" /> </appsettings> </configuration>
your aspx file can , send js :
protected void page_load(object sender, eventargs e) { clientscriptmanager csm = page.clientscript; type cstype = this.gettype(); string myvariable = configurationmanager.appsettings["my-variable"].tostring(); // add script current page before end tag </form> csm.registerstartupscript(cstype, "initvariable", string.format("window.myvariable = '{0}';", myvariable, true); }
and js, can use variable myvariable
.
Comments
Post a Comment