0

In my masterpage.cs i am assigning a value to a hidden field (hfSession="abc";)

In my content page (default.aspx) i need to access this value in my javascript:

<script type="text/javascript" language="javascript">
    function(sender, e) 
    {   
        var Sessioninfo= $get('<%= ((Hiddenfield)this.Master.FindControl("ct100_hfSession")).ClientID %>');
</script> 

but here i get an error :

object reference not set to an instance of an object

2 Answers 2

1

I use this little javascript util function:

// This function returns a control's (mangled) client id given its ASP.NET Id
function GetClientId(strid) {
var count = document.forms[0].length;
var i = 0;
var eleName;
for (i = 0; i < count; i++) {
    eleName = document.forms[0].elements[i].id;
    pos = eleName.indexOf(strid);
    if (pos >= 0) break;
}
return '#' + eleName;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Use,

Sessioninfo= $get('<%= ((Hiddenfield)this.Master.FindControl("hfSession")).ClientID %>');          

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.