Avatar of lapucca
lapucca

asked on 

How to ref asp.net web control in jQuery when Master Page and Content page are used?

The code here works prior to me breaking up my code to use Master page and the content page.  I know in jQuery I cannot use the asp.net control id any more in this.  I tried using $('<%=lsAPExerciseOptions.ClientID%>') instead of $("#lsAPExerciseOptions")  but still not working.  I appreciate some help here  to get this working again.  Thank you.
I have this script block in the Content header section.
<script type="text/javascript" language="javascript">
        $(document).ready(function() {
            $("#lsAPExerciseOptions").click(function() {

                var found = false;
                $('#lsAPExerciseOptions :selected').each(function(i, selected) {
                    if (parseInt($(selected).val()) == 11) {
                        found = true;
                    }
                });

                if (found) {

                    $("#lbOtherExercise").show();
                    $("#txtOtherExercise").show();
                }
                else {

                    $("#lbOtherExercise").hide();
                    $("#txtOtherExercise").hide();
                }

            });


            $("#lsAPDietOptions").change(function() {
                value = $(this).val();
                text = $("option:selected", this).html();
                if (value == '1') {
                    if ($('#lbPerDay').length + $('#lbPerWeek').length < 2) {
                        alert("field(s) 1 not found in the page");
                    }
                    else {
                        $('#lbPerDay').show();
                        $('#lbPerWeek').hide();
                    }
                }
                else {
                    if ($('#lbPerDay').length + $('#lbPerWeek').length < 2) {
                        alert("field(s) 2 not found in the page");
                    }
                    else {
                        $('#lbPerDay').hide();
                        $('#lbPerWeek').show();
                    }
                }

                if (value != -1)
                    if ($('#txtTarget').length < 1) {
                    alert("field(s) 3 not found in the page");
                }
                else {
                    $('#txtTarget').show();
                }
                else
                    if ($('#txtTarget').length < 1) {
                    alert("field(s) 3 not found in the page");
                }
                else {
                    $('#txtTarget').hide();
                }
            });

//            $(function() {
//                $('ul.sf-menu').superfish();
            //            });

            $(document).ready(function() {
                $('ul.sf-menu').superfish();
            }); 
            
            
        });       
        
    </script> 
</asp:Content>

Open in new window

JavaScriptASP.NET

Avatar of undefined
Last Comment
lapucca
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of lapucca
lapucca

ASKER

Hi I don't get any error but just the textboxes and the labels are not being displayed and hide when certain items are selected.  Attached is my master page and the content page where the jquery code is modified.  Thank you.
MasterPage.master
AddNewPatient.aspx
Avatar of lapucca
lapucca

ASKER

Here is the source from View Source in FF
source.txt
Avatar of lapucca
lapucca

ASKER

sorry, I forgot to mention that this program is developed using VS2008.  
Also, I checked the source and the ids do match in the JavaScript and in the code.
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo