<script type="text/javascript">
function abc()
{
var id = document.getElementById('123');
var caption= <%=MyProperty %>;
}
</script>
code behind:
protected void Page_Load(object sender, EventArgs e)
{
Page.RegisterStartupScript(Guid.NewGuid().ToString(),"<script language = 'javascript'>abc();</script>");
}
protected int MyProperty
{
get
{
return 123;
}
}
i need to pass string value to javascript, with int this codes works fine.
protected string MyProperty
{
get
{
return "123";
}
}
when i tried to pass string this code does't works.
"<script language = 'javascript'>abc();</script>". This should be"<script language='javascript' type="text/javascript">abc();</script>". You can also use this overload to automatically generate the script block:Page.ClientScript.RegisterStartupScriptBlock(typeofyourpage, "somekey", "abc();", true);