Ajax partial postback on selected row event - asp.net

I'm having a problem and I cannot understand why. I have a GridView and some other controls in an UpdatePanel. I'm trying to select a row by clicking anywere on it, so I'm using the following code to make the selection possible:
r.Attributes.Add("onclick","javascript:" + Page.ClientScript.GetPostBackEventReference(grdUtilizatori, "Select$" +r.RowIndex,true));
My problem is that the page is making full postback (the entire page is coming back from the server, not just the updatepanel).
If I'm using a simple Select command, the postback will be just partial. I compared the generated source for the page and the javascript looks identical.
Select
<tr onclick="javascript:__doPostBack('ctl00$CPH$grdUtilizatori','Select$0')">
Can you please tell me what am I doing wrong?

I found a solution on web, I've added to the update panel the following
<Triggers>
<asp:AsyncPostBackTrigger ControlID="grdUtilizatori"
EventName="SelectedIndexChanged" />
</Triggers>

Related

Control ID of aspx page

Iam not sure if it has one.It might be a stupid question.
But I want to give Triggers like this in my dropdown's Update Panel
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Control ID of Page" EventName="Load">
</Triggers>
Note: dropdown is Telerik Radcombox.
Can anyone tell me what to give in the Control ID part?
I'm not sure why you would use the Load event; events for triggers are client actions that trigger a server action, such as SelectedIndexChanged of a DropDownList when AutoPostBack="true" or Button Click event. Load happens during the natural postback and doesn't get triggered from the client. You can't specify the ClientID of the page for that reason. However, you could just use UpdateMode="Always" to always trigger asyncronous, or include more details of the problem.

How to Session a Control placed in an Update Panel to another Page

I have a panel control in which i placed a grid view control which is databinded to an SQL datasource in the code-behind file. This panel is in an update panel. I intend printing the grid view. I, however, want to session the grid view to a "Preview Page" before print it.
I followed the instruction i found in an article on printing. Here is the link to the article:
http://www.dotnetcurry.com/(X(1)S(tij3zct1vrlnntfrzfl22ko1))/ShowArticle.aspx?ID=92
The example in the article worked fine. However, mine didn't work because it's in an update panel.
Please how do i make it work. The update panel is very much needed. Please HELP!!!
From what I see on the example the main code is happends on PrintWebControl and what actually this do is do direct render the content inside a new form. This as it is you can not do it inside the UpdatePanel, but you can call it out side of UpdatePanel.
The only think that you have to do is to place the print button outside of the UpdatePanel to make a full post, or to setup UpdatePanel to not use this print control for update.
This is the button that you need to get out of UpdatePanel.
<asp:Button ID="btnPrint" runat="server" OnClick="btnPrint_Click" Text="Print" />
To make update panel to make full post back, or add this pro grammatically when the control exist on page.
<Triggers>
<asp:PostBackTrigger ControlID="btnPrint" />
</Triggers>

UpdatePanel inside a Repeater - update all rows

I'm trying to speed up my Repeater so that not as much HTML has to be resent via the AJAX UpdatePanel on each call.
So here's what I have (a very much simplified version):
<asp:Repeater ID="rptContactSteps" runat="server">
<ItemTemplate>
<p>Script:<br /><%#mobjSDIT.FormatText(Eval("script"))%></p>
<p>Notes:<br /><%#mobjSDIT.FormatText(Eval("notes"))%></p>
<asp:UpdatePanel ID="upStep" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rptContactSteps" EventName="ItemCommand" />
</Triggers>
<ContentTemplate>
<p>Contact/Step Notes:<br /><%#mobjSDIT.FormatText(Eval("contact_step_notes"))%></p>
<asp:ImageButton ID="btnSaveAndCompleteLastStep" runat="server" ImageUrl="~/images/content/buttons/save-and-complete-button.png" CommandArgument='<%#Eval("step_contact_tie_id")%>' />
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:Repeater>
So, when I click 'btnSaveAndCompleteLastStep' I want all the UpdatePanel in 'rptContactSteps' to update. Having the UpdatePanel inside the ItemTemplate should help prevent having to re-load the html/text that populates the Eval("script") & Eval("notes"), since the value of these variables could be very large and over a 3G connection this could be very costly (in time & money).
I though by adding the async trigger it'd work as I have used this type of trigger before, but not when inside the Repeater. Currently the UpdatePanels aren't getting updated at all, except from the one from which the button was pressed.
Any ideas anyone?
They aren't getting updated except by the one that is called because the update mode is set to conditional, and by default the ChildrenAsTriggers is set to true. So if you want them all to update when one of them is changed, then you will need to find each of the update panels in each of the repeater items and call .Update() on the update panel, or you can change the update mode to "Always", or just wrap your repeater in an update panel instead of wrapping just the items.
Does that make sense? If not I can expand.
That behavior sounds ok to me because postback from within an updatepanel will not update anything outside of it by default.
One way you can try is on your btnSaveAndCompleteLastStep click , find each updatepanel in the repeater items and call Update() on it.

DropDrop selection event refresh all the UpdatePanel in Ajax

I am using AJAX extension in visual studio 2005.
First of all i am created a Web custom control which contains Dropdown list.
I have also set AutoPostBack="true" for getting its SelectionEventChange event.
I am added this web control on another page inside a UpdatePanel.(i added dynamically on another page).
MyControl = (MyControl) LoadControl("MyControl.ascx")
My problem is when i select the values from dropdown it refersh my whole update panel.
What can i do please help me.
I searched in google and somebody says Use triggers
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
But on AJAX Extension i am not getting it please Help me.
Triggers tag is part of update panel. Also look at some other important properties of UpdatePanel and search on how to use and referesh nested update panels.
Add this web custom control inside another(other then one you are already having, that is, have Multiple UpdatePanels) UpdatePanel, and call .Update() manually, in order to refresh only the web control.
Dont forget to set the UpdateMode to Conditional.

Event issue with ASP.net Update Panel

I am completely stumped on this and would really appreciate any help.
I am working on a user control that is situated inside of an update panel. There is a button on the form which loads some data. This is working correctly.
There is also a drop-down box to filter the data. Changing this does initiate a post back, however nothing happens. The drop-down box goes back to it's default value the OnSelectedIndexChanged function is never called.
I've put break points in page_prerender and page_preload and both are being hit the post back is definitely occuring. Breakpoints withing the dropdownGroup_changed function are never hit.
Removing the update panel solves the problem, however it breaks the rest of the page so I can't use that for anything other than testing.
I've also verified that there is nothing in my prerender / page load that is resetting the page's state.
Here is the update panel code:
<asp:UpdatePanel ID="UpdatePanel6" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional" >
<ContentTemplate>
<ucControlName:ControlName ID="ControlName1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Here is the drop-down in question - It is located inside of the user control
<asp:DropDownList ID="dropdownGroup" runat="server" Visible="false" AutoPostBack="true" OnSelectedIndexChanged="dropdownGroup_changed"></asp:DropDownList>
It is of course visible and databound by the point in the code where the issue is occuring
A bit more info-
added Both a hard coded dropdown (To rule out a stupid databinding issue) and a textbox to the same control. I have the same issue.
It appears that the event isn't triggering because the values are never changing as far as .net is concerned. I've checked the control during page_init and page_load - the value is always the same.
The fact that the button works but the other controls don't makes me think that there is a view state issue here somewhere but I can't quite ferret out what is causing it. Viewstate is enabled for the page and the panel- don't know if anything else could be overriding / corrupting it.
Did i mention that I hate update panels with a passion? because I hate update panels with a passion.
I suggest checking the 'Value' property for each 'ListItem' in the 'DropDownList' control. If they are all the same even if the 'Text' properties are different, then the 'OnSelectedIndexChanged' will not fire at all since ASP.NET cannot tell if anything has changed (See this related question for more info.)
This was the real cause of my problem even though I, too, had a 'UserControl' with a 'DropDownList' inside an 'UpdatePanel' and the 'AutoPostBack' was firing as expected. I thought the UpdatePanel was the culprit but it was not the case. Each of the items in my DropDownList had the same underlying value of "10" even though they had distinct 'Text' values. I changed them to each have a unique value which then allowed for the OnSelectedIndexChanged event to fire thus fixing the problem.
Two answers for the price of one:
Are you calling DataBind() in your Page_Load? If you do that on a PostBack, you will lose events. Replace the call with the following:
if (!IsPostBack) {
DataBind();
}
If your DropDownList is outside your UpdatePanel, you need to add a Trigger as follows:
<asp:UpdatePanel ID="UpdatePanel6" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="dropdownGroup" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<ucControlName:ControlName ID="ControlName1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Have you tried UpdatePanel.Update (); after your databind.

Resources