Josh Mein
Josh Mein

Reputation: 28625

Entire Page refreshes even though gridview is in an update panel

I have a gridview that is within an updatepanel for a modal popup I have on a page.
The issue is that the entire page refreshes every time I click an imagebutton that is within my gridview. This causes my entire page to load and since I have grayed out the rest of the page so that the user cannot click on it this is very annoying.

Does any one know what I am missing.

Edit: I entered a better solution at the bottom

Upvotes: 2

Views: 6916

Answers (11)

user21308979
user21308979

Reputation: 1

In my case this works for me:

change in the web.config

    <xhtmlConformance mode="Transitional"/>

    'default.aspx 
    asp:GridView ID="GridView1" runat="server" Width="940px" 
    HorizontalAlign="Center" 
    OnRowCommand="GridView1_RowCommand" AutoGenerateColumns="false" 
    AllowPaging="true" PageSize="5"
    DataKeyNames="idarea" CssClass="table table-hover table-striped"
    OnPageIndexChanging="GridView1_PageIndexChanging" 

    'default.aspx.vb
   Protected Sub GridView1_PageIndexChanging(sender As Object, e As 
        GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        BindGrid()
        GridView1.PageIndex = e.NewPageIndex
        GridView1.DataBind()
   End Sub

Thanks for tip. Luis Palencia

Upvotes: 0

Elim Garak
Elim Garak

Reputation: 1817

To prevent post-backs add return false to the onclick event.

button.attribute.add("onclick","return false;");

Sample:

string PopupURL = Common.GetAppPopupPath() + "Popups/StockChart.aspx?s=" + symbol;
hlLargeChart.Attributes.Add("onclick", String.Format("ShowPopupStdControls(PCStockChartWindow,'{0}');return false;", PopupURL));

Upvotes: 0

Scotty.NET
Scotty.NET

Reputation: 12561

For reference..

I've also noticed, when using the dreaded <asp:UpdatePanel ... /> and <asp:LinkButton ... />, that as well as UpdateMode="Conditional" on the UpdatePanel the following other changes are required:

  • ViewStateMode="Enabled" is required on <asp:Content ... /> (I've set it to Disabled in the MasterPage)
  • ClientIDMode="Static" had to be removed from <%@ Page ... />

Upvotes: 0

Josh Mein
Josh Mein

Reputation: 28625

Several months later this problem was fixed. The project I was working in was a previous v1.1 which was converted with 2.0. However, in the web.config this line remained:

<xhtmlConformance mode="Legacy"/>

When it was commented out all of the bugs that we seemed to have with the ajax control toolkit disappeared

Upvotes: 1

bitsprint
bitsprint

Reputation: 897

I had this problem and came across the following article:

http://bloggingabout.net/blogs/rick/archive/2008/04/02/linkbutton-inside-updatepanel-results-in-full-postback-updatepanel-not-triggered.aspx

My button wasn't dynamically created in the code like in this example, but when I checked the code in the aspx sure enough it was missing an ID property. On adding the ID the postback became asynchronous and started to behave as expected.

So, in summary, check your button has an ID!

Upvotes: 2

Compulsion
Compulsion

Reputation: 133

UpdatePanels can be sensitive to malformed HTML. Do a View Source from your browser and run it through something like the W3C validator to look for anything weird (unclosed div or table being the usual suspects)

If you use Firefox, there's a HTML validator Extension/AddOn available that works quite nicely.

Upvotes: 0

Steven Williams
Steven Williams

Reputation: 1014

I would leave the onClick and set it as the trigger for the updatePanel.

That's odd that it works in FF and not IE. That is opposite from the behavior we experience.

Upvotes: 0

Steven Williams
Steven Williams

Reputation: 1014

Are you testing in Firefox or IE? We have a similar issue where the entire page refreshes in Firefox (but not IE). To get around it we use a hidden asp:button with the useSubmitBehavior="false" set.

<asp:Button ID="btnRefresh" runat="server" OnClick="btnRefresh_Click" Style="display: none" UseSubmitBehavior="false" />

Upvotes: 1

Compulsion
Compulsion

Reputation: 133

Make sure you have the following set on the UpdatePanel: ChildrenAsTriggers=false and UpdateMode=Conditional

Upvotes: 3

David Basarab
David Basarab

Reputation: 73301

Is the Modal Window popped up using the IE Modal window? Or is it a DIV that you are showing?

If it is an IE Modal Pop up you need to ensure you have

   <base target="_self" /> 

To make sure the post back are to the modal page.

If it is a DIV make sure you have your XHTML correct or it might not know what to update.

Upvotes: 0

Ben Scheirman
Ben Scheirman

Reputation: 40951

do you have ChildrenAsTriggers="false" on the UpdatePanel?

Are there any javascript errors on the page?

Upvotes: 2

Related Questions