Solved

Adding jquery blocks __doPostback on aspx server generated objects

Posted on 2011-02-17
3
982 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now