ListView in UpdatePanel not Refreshing - asp.net

I have a ListView that's inside a UpdatePanel, UpdateMode = Conditional. It's a really large Listview, lots of templates, so I'm not showing details.
<asp:UpdatePanel ID="updListView" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ListView ID="lstvScanPreview" runat="server" OnItemDataBound="lstvScanPreview_ItemDataBound">
...
</ContentTemplate>
</asp:UpdatePanel>
I also have a radiobutonlist outside of the update panel with a OnSelectedIndexChanged of
protected void rgbShowIssues_SelectedIndexChanged(object sender, EventArgs e)
{
if (rgbShowIssues.SelectedIndex == 0)
lstvScanPreview.DataSource = previewData.Data.Where(S => S.IssueType != ScanIssues.None);
else
lstvScanPreview.DataSource = previewData.Data;
updListView.Update();
}
A breakpoint set inside this method does get hit, but the listview doesn't refresh. Other controls also have events with code-behind that call updListView.Update(), and these do work. If I trigger one of these other events after I clicking on the rgbShowIssues radiobuttonlist, then when the update does occur, I can see the changes I would have expected had the UpdatePanel refreshed when expected.
Any ideas why this isn't working? Thanks.

Related

Unable to update label in update panel from user control ASP.net

My code is as follows.
<div class="table">
<asp:UpdatePanel runat="server" ID="labelPanel" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Label Text="" runat="server" ID="Cost"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<uc1:ucPartsListing ID="ucPartsListing" runat="server" />
</div>
Now the usercontrol ucPartsListing itself has 2 update panels. There is an event fired from the user control to parent aspx for some conditions.
In that event, I am trying to set the label value which is present in aspx file. I am calling update manually from code-behind. Yet it doesn't work. Where am I going wrong ?
public partial class PartsEnquiry : BaseAuthPage
{
protected void Page_Load(object sender, EventArgs e)
{
ucPartsListing.OnQuotePartsItemSelect += new ascx.ucPartsListing.QuotePartsItemEventHandler(ucPartsListing_OnQuotePartsItemSelect);
}
void ucPartsListing_OnQuotePartsItemSelect(string price)
{
Cost.Text = price; //This is not working !
labelPanel.Update();
}
Set a breakpoint on your "void ucPartsListing_OnQuotePartsItemSelect(string price)" method and see if it gets hit at all.
I'm not sure what the user control is that you are using, but whatever control it is that is supposed to fire the event, try setting its AutoPostBack property to True.
I think you are out of luck with your current structure.
When the UpdatePanel inside you user control is fired in the browser, it will update the part of the page that is inside itself. You cannot update controls that are outside of the executing UpdatePanel.
Manually calling the Update() method on the outer UpdatePanel will not help since on the client it is still one of the inner UpdatePanels that is receiving the output back and updating the html tree.
To get it to work you will have to somehow trigger the outer UpdatePanel which will be able to update the Cost label.

asp.net : exclude control in updatepanel from doing async postback

I have placed a user control inside update panel after doing asynchronous postback of page associated js file of that user control is not working so that is there any method to exclude a control from updatepanel in another word i don't want to post that user control.
<asp:UpdatePanel ID="upPnlAnswerList" runat="server">
<ContentTemplate>
// another code that required to placed inside updatepanel
<div id="miancontainer" class="containerr"
<klmsuc:Share ID="shareUserControl" runat="server" />
// another code that required to placed inside updatepanel
</div>
Use a PostBackTrigger to perform exclusion rather than having to specify a large number of includes.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:LinkButton ID="lnkExport" runat="server" OnClick="lnkExport_Click" Text="Export Data"></asp:LinkButton>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="lnkExport" />
</Triggers>
</asp:UpdatePanel>
Set UpdateMode=Conditional and provide exclusive Triggers for the UpdatePanel.
See:
http://msdn.microsoft.com/en-us/library/bb386454.aspx
you must add some controls in code behind and in the right event and register it for exclusion(postback) instead and AsyncPostBack which is a ajax call.
ScriptManager.GetCurrent(this).RegisterPostBackControl(btnAdd);
https://stackoverflow.com/a/23036830/184572
protected void grdExpense_RowCreated(object sender, GridViewRowEventArgs e)
{
LinkButton btnAdd = (LinkButton)e.Row.Cells[0].FindControl("btnAdd");
if (btnAdd != null)
{
ScriptManager.GetCurrent(this).RegisterPostBackControl(btnAdd);
}
}
look for another similar page which excludes all the controls in a gridview
http://www.aspsnippets.com/Articles/Assign-PostBack-Trigger-Full-PostBack-for-LinkButton-inside-GridView-within-AJAX-UpdatePanel-in-ASPNet.aspx
private void RegisterPostBackControl()
{
foreach (GridViewRow row in GridView1.Rows)
{
LinkButton lnkFull = row.FindControl("lnkFull") as LinkButton;
ScriptManager.GetCurrent(this).RegisterPostBackControl(lnkFull);
}
}

Timer in UPdatePanel changes selectedIndex of RadioButtonList

I have a situation where I have a page in ASP.NET. In this page I have a RadioButtonList, which contains 5 solutions to a question. The RadioButtonList is feeded by an object, which has these solutions.
I have a timer, which runs every second, to update loads of graphical controls. Everything works, BESIDES the RadioButtonList selection.
This is what happends:
When I select an item in the RadioButtonList and the timer tick, the selectedIndex of the RadioButtonLIst value is 0.
This means it selects the FIRST item in the list. However, IF I click an item, which has a "Yes" value in it (the value field can either have "No" or "Yes", it will stay at this item.
First of all, I have NO idea why the timer re-select my RadioButtonList selection, as any other Page_Load event does nothing. And even if that makes sense, I have no idea why it just re-selects SOME of the answers..
I have the following HTML code:
<asp:Timer ID="AssignmentTimer" runat="server" Interval="1000">
</asp:Timer>
<asp:UpdatePanel ID="FightUpdatePnl" runat="server" UpdateMode="Always" ChildrenAsTriggers="True">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="AssignmentTimer" EventName="Tick"/>
</Triggers>
<ContentTemplate>
<asp:Panel ID="AssignmentDiv" runat="server" CssClass="FightDiv">
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
I have the following code behind:
protected void Page_Load(object sender, EventArgs e)
{
SetupPage();
}
private void SetupPage()
{
RadioButtonList list = new RadioButtonList();
list.DataSource = question.PossibleSolution;
list.DataTextField = "Content";
list.DataValueField = "IsAnswer";
list.DataBind();
AssignmentDiv.Controls.Add(list);
}
So, to summarize, my problem is...
When the timer ticks, the RadioButtonList re-select item 0. This is however not consistent, and sometimes it doesn't re-select.
I'd rather it didn't re-select at all! :)
I'm not sure if there are not other possible causes, but you should not bind your RadioButtonList in Page_Load on postbacks.
Otherwise the selection get lost.
if (!IsPostBack) {
SetupPage();
}
Do that only when the page get first loaded and when you change its datasource(f.e in event-handler where you update the questions).
You are adding the RadioButtonList dynamically to the page. Ok, this have to be done on every postback(in Page_Init if possible). But it don't need to be rebound to the datasource on every Postback, because the Viewstate will save the selection on Postbacks. So split the (re)creation and adding of the RadioButtonList from the RadioButtonList.DataBind. The first have to be done on every postback and the second only on first load and when the source has changed(f.e. in an event handler).
Set the ID of the RadiobuttonList. Otherwise the ViewState will not be loaded after postback. The ID should be unique. If you are adding more than one RadioButtonList use a counter or such a thing.

UpdatePanel wrapped around a user control

I have a user control which contains some buttons and a placeholder. Those buttons cause controls to be added/removed from placeholder. Everything works fine.
Now I want to put this user control in a page, and wrap it in an updatepanel like so:
<asp:UpdatePanel ChildrenAsTriggers="true" ID="UpdatePanelFoo" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<grid:tablegrid ID="tablegrid_chapters" runat="server" SomeProperty="bar" />
</ContentTemplate>
</asp:UpdatePanel>
When I run the page, it's still doing a full postback when I hit one of the buttons inside the user control. What am I doing wrong, and how can I remedy this?
Update:
protected void Page_Init()
{
ScriptManager scr = ScriptManager.GetCurrent(this.Page);
Response.Write("EnablePartialRendering: " + scr.EnablePartialRendering);
}
Outputs "EnablePartialRendering: true"
Make sure you have EnablePartialRendering=true on your ScriptManager in the page.
Update
It looks like your UserControl has no events to be looking for...you have 2 options here. Move the UpdatePanel inside the UserControl .ascx so it can see the button events as children to rig up or add an event for it to see, to do that try something like this:
public event EventHandler Click;
void btn_del_Click(object sender, EventArgs e)
{
if (NumberOfRowControls > 0)
{
var rowToWhack = panel_rows.Controls.Children().Single(x => x.ID == "myrow" + (NumberOfRowControls - 1));
panel_rows.Controls.Remove(rowToWhack);
NumberOfRowControls--;
}
if(Click != null) Click(this, e);
}
void btn_add_Click(object sender, EventArgs e)
{
var row = NewRow(NumberOfRowControls);
panel_rows.Controls.Add(row);
if(Click != null) Click(this, e);
}
And update the UpdatePanel to be looking for it:
<asp:UpdatePanel ID="UpdatePanelFoo" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<grid:tablegrid ID="tablegrid_chapters" runat="server" SomeProperty="bar" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="tablegrid_chapters" EventName="Click">
</Triggers>
</asp:UpdatePanel>
Make sure you add a ScriptManager as well to the page, otherwise there's no UpdatePanel functionality.

ASP.NET: "Object Required" when repeating LinkButtons in an UpdatePanel

I have an UpdatePanel which has a Repeater repeating LinkButtons. When I click a LinkButton, the page does a partial postback, then I get a javascript error: "Object required". I tried debugging the javascript, but couldn't get a call stack. If I remove the UpdatePanel, the LinkButtons do a full postback, and they disappear from the page. How can I get this UpdatePanel to work?
<ajax:UpdatePanel ID="wrapperUpdatePanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Repeater ID="endpointRepeater" runat="server" OnItemDataBound="EndpointDataBound">
<HeaderTemplate>
<div class="sideTabs">
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:LinkButton ID="endpointLink" runat="server" OnClick="EndpointSelected" />
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</div>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</ajax:UpdatePanel>
binding code:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.SelectedEndpoint = Factory.Get<IEndpoint>(Enums.EndPoints.Marketing);
}
IEndpointCollection col = EndpointCollection.GetActivelySubscribingEndpointsForPart(this.Item);
if (this.Item.IsGdsnItem)
col.Add(Factory.Get<IEndpoint>(Enums.EndPoints.Gdsn));
if (col.Count > 0)
col.Insert(0, Factory.Get<IEndpoint>(Enums.EndPoints.Marketing));
this.endpointRepeater.DataSource = col;
this.endpointRepeater.DataBind();
if (this.endpointRepeater.Items.Count > 0)
{
LinkButton lb = this.endpointRepeater.Items[0].FindControl("endpointLink") as LinkButton;
this.EndpointSelected(lb, new EventArgs());
}
}
thanks,
mark
This may not be your main issue, but when including an object inside a Repeater that needs an event, you shouldn't be using that control's native events. Instead you should use the Repeater's OnCommand event.
If I were to guess, your problem is caused by the repeater not maintaining its DataBound state across PostBacks. The Linkbutton disappears from view because it is not bound to the page on every PostBack, so when the response is sent back to the client, it has nothing bound to it.
It sounds like the UpdatePanel is expecting the same (or similar) markup to be returned from the AJAX response as what is on the page already, so returning nothing for the repeater causes problems.
Try binding your repeater to the page/control in its OnInit() method. This should allow the ViewState for the repeater to be loaded on every PostBack.

Resources