I get a data from database in aspx.cs like:
string abc = sdr["aaa"].ToString()
How can I call "string abc" in javascript part
thanks for answers
Simply render out your C# variable to the page so you can access it via JavaScript.
In .aspx.cs:
protected string abc {get;set;}
protected void Page_Load(object sender, EventArgs e)
{
var sdr = GetData();
abc = sdr["aaa"].ToString();
}
In .aspx:
<script>
var abc = '<%=abc%>';
alert(abc);
</script>
Try with ClientScriptManager.RegisterStartupScript. ( http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx )
使用此代码:
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script language='javascript'>alert(" + abc + ");</script>", false)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.