Solved

Adding jquery blocks __doPostback on aspx server generated objects

Posted on 2011-02-17
3
997 Views
Last Modified: 2012-05-11
Hi experts,

Hi have an aspx page with a repeater binded to a database:

<asp:Repeater runat="server" ID="repeaterMenu" DataSourceID="sdsApartats" OnItemDataBound="repeaterMenu_ItemDataBound" >
    <ItemTemplate>
        <tr id="trMenu">
            <td class="tdMenu">
                <asp:Panel ID="divMenu" runat="server" CssClass="menu" >
                    <asp:LinkButton ID="lbMenu" runat="server" CssClass="menu" OnClick="lbMenu_Command" CommandArgument=<%# Eval("idApartat") %>>
                        &nbsp; <%# Eval("titol").ToString().PadLeft(30,' ') %> &nbsp;
                    </asp:LinkButton>
                </asp:Panel>
            </td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

Open in new window


A bit forward I need a jquery animation so I add a jquery reference in the header:

<script src="Scripts/jquery-1.4.1.js" />

Open in new window


Only with this reference to jquery in the header, every time I run the application the page renders OK, but it raises an error:

Microsoft jscript runtime error: object expected

Open in new window


with debugger stopped at:

__doPostBack('ctl00$repeaterMenu$ctl00$lbMenu','')

Open in new window


I supose jquery gets somehow confused with the "$" separator in the sender's ID.
I've googled and even ee-ed and found no clue.

Can someone put a little light on this. An answer will be fully appreciated.
0
Comment
Question by:Catalaziz
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
BurnieP earned 250 total points
ID: 34921887
Hi,

You might have some conflict with another javascript library in your project.  You can try setting the noConflict to JQuery after your JQuery reference :

<script src="Scripts/jquery-1.4.1.js" />
<script type="text/javascript">
  $.noConflict();
</script>
0
 

Author Comment

by:Catalaziz
ID: 34924379
Thanks BurnieP,

There is no other library javascript library in this project.
You can easily repeat this behaviour by:

1. Create a new web site in Visual Studio .net framework 3.5.
2. In the default.aspx webform add a sqldatasource (or any other database binding object)
3. Add a repeater that generates a linkbutton for each record in the datasource object.
4. Link the command event handler of each linkbutton generated. Or use the itemcommand of the repeater; it makes no difference.
5. Add a reference to jquery in the head section of the aspx code.
6. Add a simple jquery animation at the document.ready jquery event.

That's all. Page renders OK but if you click on any of the generated buttons, you'll get the error.

Adding $.noConflict() gets postback running again, but any other jquery function (that simple animation at the document.ready event) stops working.

If I remove the asp:repeater, then the jquery code works fine, but I need those asp:repeater generated linkbuttons
0
 

Author Closing Comment

by:Catalaziz
ID: 34924396
Sorry for this section in my last comment:

"Adding $.noConflict() gets postback running again, but any other jquery function (that simple animation at the document.ready event) stops working."

The animation wasn't working because of a bug in the code of the animation.

You nailed it BurnieP!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question