Retrieve page public property from jquery

I have a master page with the following code.

 Public Property UserType As String
        Get
            Return mUserType
        End Get
        Set(value As String)
            mUserType = value
        End Set
    End Property


Now I can of course access that property when a page loads.  So when I load the content page, I assign the usertype ="P"

So after content page loads I need jquery on Master page to run that looks at the usertype and hides a <ul> with the ID of "type"

So I need a document.ready script on the master page that can get the value of usertype and either hide or show based on the value c or p

I know how to do it with a control, but not sure with a property value.

thanks
mgmhicksAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Duy PhamFreelance IT ConsultantCommented:
One simple way is to use Hidden field to stored that property rather than a member variable.
In your .aspx, add a Hidden field
...
<asp:Hidden ID="hfUserType" runat="server" Value="" />
...

Open in new window


In your .aspx.vb file, change the code of UserType property as below:
Public Property UserType As String
         Get
             Return hfUserType.Value
         End Get
         Set(value As String)
             hfUserType.Value = value
         End Set
End Property

Open in new window

SwapnilSoftware ArchitectCommented:
I have formulated the code based on your requirement however please change the condition based on your exact requirement. Please let me know in case you face any issue in below code.

In your master page's code behind, added one line in your code

Public Property UserType As String
        Get
            Return mUserType
        End Get
        Set(value As String)
            mUserType = value
            hdnUserType.Value = value;        
        End Set
    End Property

Open in new window


In your master page html
<input name="hdnUserType" type="hidden" id="hdnUserType" value="" runat="server" />
<ul id="type">
<li>Item1</li>
<li>Item2</li>
</ul>

Open in new window


in javascript section
$.ready({
if($('#hdnUserType').val() == 'P')
    $('#type').show();
else
      $('#type').hide();
});

Open in new window


Thanks,
NetSwap
ArkCommented:
Some other ways:

1. use Literal control:
<asp:Literal ID="Literal1" runat="server"></asp:Literal> (place it in the <head> part of .aspx file to load it before page)
Code behind:
Literal1.Text = StringFormat("<script language=""javascript"">var myVar = {0};</script>", UserType)

2. Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "myUserType", "var myVar=" & UserType, True)

3. In .aspx page:
<script type="text/javascript" >
    var myVar = "<%= UserType %>";
</script>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.