JQuery object expected error in an ASP.net usercontrol

Go To StackoverFlow.com

0

I have 2 pages that has a huge dynamic generated table on each. The tables are almost identical so instead of having the code in two places, I am making the table a user control that can be added to each page.

There is some client side script that changes row color or hides and shows text based on radio button clicks. The code works perfectly in the original aspx page but in the new page that has the user control in it I get Object Expected in this code on the if line.

var controlName = "AdditionalQuestionTable" + QuestionNumber + "_Yes";
if ($('#' + controlName).get(0) != null)
    {
        $('#' + controlName).get(0).className = 'visible';
    }

I have ClientIDMode set to Static on both and I can see the ids are the same on both pages. I am stumped. When I do View Source and look at the rendered code for each they are identical as shown below.

<table id="AdditionalQuestionTable3_Yes" class="hidden" style="width:100%;">


<table id="AdditionalQuestionTable3_Yes" class="hidden" style="width:100%;">

Any help would be greatly appreciated. Thanks.

Rhonda

2012-04-05 20:27
by Rhonda
how does the variable "QuestionNumber " get set - Dave D 2012-04-06 00:17
It's a parameter that gets passed in on the click event - Rhonda 2012-04-06 16:03
The only other thing i can think of, is make sure you have the jQuery js file loaded on the second page - Dave D 2012-04-06 18:33
Another thing that is interesting. If I do this if (document.getElementById(controlName) != null) { document.getElementById(controlName).className = 'hidden'; } It works - Rhonda 2012-04-06 18:56
Well then it definitely sounds like your jquery script is missing / failed to load. But doesn't sound like it either - Dave D 2012-04-06 19:01
Oh good grief! That was exactly it. I had the link to my js file but forgot to put the link to the jquery-1.4.1.js file. I am using a test page and forgot to add it there. DORK!!! Thanks for the help. I should have read you comment above when I posted the comment about getElementById. Would have saved me some time but I didn't actually see it then. DOH - Rhonda 2012-04-06 19:15


1

The Object Expected was caused by the jquery script file missing.

2012-04-06 20:31
by Dave D
Ads