Reputation:
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
Upvotes: 5
Views: 3581
Reputation: 31353
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>
Upvotes: 3
Reputation: 3223
Use this code:
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script language='javascript'>alert(" + abc + ");</script>", false)
Upvotes: 0
Reputation: 688
Try with ClientScriptManager.RegisterStartupScript. (http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx)
Upvotes: 0