Home How to get value of a control in a Masterpage using JQuery?
Reply: 3

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

Theomax
1#
Theomax Published in 2012-04-27 11:56:45Z

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?

Jamie Dixon
2#
Jamie Dixon Reply to 2012-04-27 12:00:53Z

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.

Paul Grimshaw
3#
Paul Grimshaw Reply to 2012-04-27 12:00:34Z

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.

FishBasketGordo
4#
FishBasketGordo Reply to 2012-04-27 12:12:05Z

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.70394 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO