[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

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

0
lapucca
Asked:
lapucca
  • 3
1 Solution
 
strickddCommented:
If you are using .Net 4, you can try setting the ClientIDMode to "Static" on the controls. http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx

<%=lsAPExerciseOptions.ClientID%> should work, what type of error are you getting? Have you viewed the source to make sure that the ID and the value printed in javascript match?
0
 
lapuccaAuthor Commented:
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
0
 
lapuccaAuthor Commented:
Here is the source from View Source in FF
source.txt
0
 
lapuccaAuthor Commented:
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now