Theomax
Theomax

Reputation: 6810

How to get value of a control in a Masterpage using JQuery?

I have a hidden field control in a MasterPage and I want to get the value of the hidden field control using JQuery in a page that uses the MasterPage.

I have the following javascript which exectues if the hidden field in the page has a value:

if(!$('input[type=hidden]').val().length == 0 ) { } 

What javascript would I need to check the value of a hidden field in the MasterPage from the page?

Upvotes: 3

Views: 1333

Answers (3)

FishBasketGordo
FishBasketGordo

Reputation: 23142

The master page just gets rendered down with the child page as a single HTML, so you would just access it client-side as normal.

Try rewriting this:

if(!$('input[type=hidden]').val().length == 0 ) { }

as

if ($('input[type=hidden]').val()) {}

which is a simpler conditional for if the hidden field has a value. I'm not sure that the ! combined with the == is doing what you want it to do logically. Either way $('input[type=hidden]').val() is more readable IMO.

Upvotes: 2

Jamie Dixon
Jamie Dixon

Reputation: 54021

There's no seperation between your page and the master page. Both of those concepts are in your ASP.NET layer and the browser simply recieves one HTML document.

If your masterpage specified a hidden input it'll be on your page like any other hidden input.

Upvotes: 3

Paul Grimshaw
Paul Grimshaw

Reputation: 21044

If that has the affect you want, it should also work in the masterpage, as there is no difference on the client between a master and a content page.

Upvotes: 3

Related Questions