I'm just doing :
Javascript:
function assign(){
var sHidVar = 'something';
document.getElementById('<%=hdnPage.ClientID%>') = sHidVar ;
alert(document.getElementById('<%=hdnPage.ClientID%>'));
}
ASPX
...
<asp:HiddenField ID=hdnPage runat=server />
...
Here is the problem when I do this:
ASPX :
<a href=# önclick="Javascript:assign();">Test</a>
it runs fine, the variable is assigned and I can access from CodeBehind by:
string s = hdnPage.Value;
but, to run this function on page load like :
protected void Page_Load(object sender, EventArgs e)
...
ClientScript.RegisterClientScriptBlock(this.GetType(), "assign", "assign();", true);
..
}
it gives an error, saying document.getElementById(...) is not an object
how else can I call the function on page load, of is there something wrong with the function
PS: Also tried the
$('<%=hdnPage.ClientID%>')
, doesn't work