AJAX rating control inside update panel leads to reload the complete page - c#

I have used AJAX Rating control for star rating. I am trying to achieve rating without page postback, therefore I placed inside update panel but still page is used to reload.
Below is aspx page code:
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<cc2:Rating ID="Rating1" AutoPostBack="true" OnChanged="OnRatingChanged" runat="server"
StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star" FilledStarCssClass="FilledStar">
</cc2:Rating>
<div style="text-align: left; padding-right: 2px;">
<asp:Label ID="lblRatingStatus" runat="server" Text=""></asp:Label>
</div>
</ContentTemplate>
</asp:UpdatePanel>

Change update mode of updatepanel from conditional to always and set ChildrenAsTriggers="True". Should work in your case.
Let me know if it doesn't work.

Related

Could not find UpdatePanel with ID on page postback

I have below structure in my asp.net application.
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="overlay"></div>
<asp:Panel ID="pnlMain" runat="server" Visible="true">
<asp:UpdatePanel ID="upProfile" runat="server" UpdateMode="Always">
<ContentTemplate>
<div>
<table>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upAttachment" runat="server" UpdateMode="Always">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:Panel ID="pnlSuccessMessage" runat="server" >
<asp:Label ID="lblSuccessMessage" runat="server"></asp:Label>
</asp:Panel>
I have different textfields and dropdowns in the table of upProfile updatepanel and file upload control in upAttachment updatepanel. Now when I select one radio from the same update panel, I am getting below error and the upAttachment does not show up on page.
Uncaught Error: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'MainContent_upAttachment'. If it is being updated dynamically then it must be inside another UpdatePanel.
I have searched a lot and tried below different things, but still it is not working
1. Set the upAttachment UpdateMode to Conditional.
- In this case, it does not throw error, but the file upload control which is inside that updatepanel, it does not show up
2. Place the upAttachment updatepanel inside another updatepanel, but that too is not working.
I don't know what to do in this case. Can anyone help me on this?

User Control, Delegate and UpdatePanel Issue

I am currently running up against a problem with the UpdatePanel. One of my pages has two User Controls I'll call A and B.
The User Control A has an UpdatePanel containing several ASP TextBox.
<asp:UpdatePanel ID="upA" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" style="position: relative;">
<ContentTemplate>
<-- content here -->
</ContentTemplate>
</asp:UpdatePanel>
The User Control B has an UpdatePanel containing a Panel and an AjaxModalPopup linked to it. In the Panel, there is a Repeater and an ASP button.
<asp:UpdatePanel runat="server" ID="upB" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnActivePopupContainer" runat="server" Style="display: none;" />
<asp:Panel ID="pnlPopupContainer" runat="server" CssClass="modalPopup modalPopupDraggable" Style="display: none;" Width="750px">
<asp:UpdatePanel ID="upPopup" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel runat="server" ID="pnlHeader" class="header">
<asp:Label ID="Label1" runat="server" Text="<%$ Resources:global, AttentionPopup %>"></asp:Label>
</asp:Panel>
<article>
<asp:Repeater runat="server" ID="rptPopup" OnItemDataBound="rptPopup_ItemDataBound">
<ItemTemplate>
<-- Content -->
</ItemTemplate>
</asp:Repeater>
</article>
<footer>
<div class="or-spacer">
<div class="mask"></div>
</div>
<div class="footer">
<asp:Panel runat="server" ID="pnlBtnBug">
<asp:Button ID="btnOK" runat="server" CssClass="btn yes" Text="<%$ Resources:global, Ok %>" OnClick="btnOK_Click" />
</asp:Panel>
</div>
</footer>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<ajax:ModalPopupExtender ID="popupContainer" runat="server" BackgroundCssClass="modalBackground" PopupControlID="pnlPopupContainer" TargetControlID="btnActivePopupContainer" Drag="true" PopupDragHandleControlID="pnlHeader"></ajax:ModalPopupExtender>
</ContentTemplate>
When the user clicks the OK button of the UserControl B, it triggers a delegate that calls a method in the UserControl A that performs updating of some fields and the update method of the UpdatePanel "upA".
The delegate:
//Delegate Call When the user clicks the ok Button
popup.okHandler = (x) =>
{
A.ChooseOpticienCode(x.Value);
};
in the UserControl A's code behind:
public void ChooseOpticienCode(string code)
{
<-- some treatments -- >
upOpticien.Update(); <-- crash here
}
When the method upOpticien.Update() is called, I get this error:
System.InvalidOperationException: The Update method can only be called on UpdatePanel with ID 'upOpticien before Render.
I don't understand why I get this error. I tried to set the UpdateMode of the UpdatePanel to "Always", the application no longer crashes but the fields are not updated.
ideas ?
I finally found how to fix my problem. Instead of calling the delegate directly, I must use the InvokeMember function so that the delegate is executed correctly and can edit the various fields and update the UpdatePanel
page.GetType().InvokeMember(OkHandler.Method.Name, System.Reflection.BindingFlags.InvokeMethod, null, page, new[] { this });
(here, OkHandler is my delegate)
However, note that using an anonymous method will not work, it's imperative that the delegate points to a method with a name for InvokeMember works.

"<!" character combination in ASP.NET textbox prevents postback

So this is very strange, and I haven't been able to find anything about it while searching.
I have an ASP.NET webforms app, and I am using the AJAX Control Toolkit's Modal Popup extender. Inside of this popup, I have a multi line textbox and some buttons. Both are ASP control. I have found that after entering the character combination "
Here is a picture of the dialog:
The dialog that won't work
And here is the markup for it:
<div id="notes" style="display: none">
<asp:UpdatePanel id="upnlNotesHeader" runat="server" class="logHeader">
<ContentTemplate>
<asp:Label ID="lblNotes" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<div class="logBody" style="height:200px">
<asp:UpdatePanel ID="upnlNotes" runat="server">
<ContentTemplate>
<asp:HiddenField ID="hdnNotesJswo" runat="server" />
<asp:TextBox ID="txtNotes" runat="server" TextMode="MultiLine" MaxLength="4000" Font-Names="Arial" Rows="12" Columns="62" style="margin: 5px 0 0 5px"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="logBtns">
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Button ID="btnSaveNotes" runat="server" Text="Save" CssClass="logBtn" OnClick="btnSaveNotes_Click" />
<asp:Button ID="btnCancelNotes" runat="server" Text="Cancel" CssClass="logBtn" OnClick="btnCancelNotes_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
Does anyone know why this is happening?
The problem comes from the request validation performed by ASP.NET when submitting the page. You can turn it off at the page level like this:
<%# Page ValidateRequest="false" ... %>
An alternative, if you want to keep the validation, is to encode the content of the fields before submitting the form to the server, and decode it in code-behind.

Button postback getting error

I have a updatepanel with a listview inside. This panel refreshes with an interval of 10 seconds, and listview source is updated and rebinded. My listview have some imagebuttons, and here comes the problem. When I click any of the listview buttons, I get a error:
"Invalid postback or callback argument." error.
I'm trying everything that I see on my serches, and no, I'll not set validation to false.
Here's a simplified template of my list.
<asp:UpdatePanel runat="server" ID="pnlRegistro" ClientIDMode="Static" OnLoad="pnlRegistro_Load">
<ContentTemplate>
<asp:ListView runat="server" ID="lvRegistro" OnPreRender="lvRegistro_PreRender" >
<LayoutTemplate>
<!-- Unread notification count -->
<span runat="server" id="spanRegistroCount" class="mws-dropdown-notif">
<asp:Label ID="lblRegistroCount" runat="server" Text="0"></asp:Label>
</span>
</LayoutTemplate>
<ItemTemplate>
<li class="<%# Convert.ToInt32(Eval("RegistroHorarioId"))==0?"read":"unread"%>">
<a>
<div style="width: 80%; float: left;">
<span class="message" <%#Eval("SpanColor")%>>
<%#Eval("Status")%>
</span>
</div>
<div style="float: right">
<asp:ImageButton runat="server" ID="btnRegistro" OnClick="btnRegistro_Click"/>
</div>
</a>
</li>
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
What can I do to fix this error and fire "btnRegistro_Click" event?
Update Panel is used for Updating Partial Page instead of doing full postback.
So,you have to add PostBackTrigger sync or async whatever you want because you are using update panel and for update panel events are defined in triggers to avoid full postback, so most probably you want asnc postback trigger.
add trigger for button event after content template end tag (</ContentTemplate>):
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnRegistro" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
you should also read Understanding ASP.NET AJAX UpdatePanel Triggers

stopping page refresh at each click

I have a page name ask.aspx
I have 4 list views in that page which are binding at the time of page load event.
now when ever i click on the items of list view i get the whole page refreshed.
I have used the update panel but for some reasons it is not working
The code for the same is given below.
aspx page
enter code here
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<legend><asp:Label ID="Label1" runat="server"></asp:Label></legend>
<ul class="tags">
<asp:ListView ID="ListView1" runat="server" OnItemCommand="ListView1_ItemCommand" >
<ItemTemplate>
<li><asp:LinkButton ID="LinkButton2" runat="server" CommandArgument='<%# Eval("CategoryId") %>'><%# Eval("Name") %></asp:LinkButton></li>
</ItemTemplate>
</asp:ListView>
</ul>
</fieldset>
</ContentTemplate>
<Triggers></Triggers>
</asp:UpdatePanel>
ending the content template and update panel.
similarly for the other three listviews.
at cs page
some calculations are taking place.
Now i dont want the page to refresh every time.
what should be done.
please suggest.
Remove childrenastrigger property and set updatemode=always

Categories