DropDrop selection event refresh all the UpdatePanel in Ajax - asp.net

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.

Related

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>

Ajax partial postback on selected row event

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>

ASP.NET - reload a dropdown?

I have a dropdown which shows filesnames and when the index is changed, the slected file is offered for download. I also have a button which creates new files ... now after a new file was created, the new filename should also be shown in the dropdown. It works fine, when I refresh the page, but this is not what I want.
I tried putting the dropdown in an updatepanel and giving it the file create button id, it failed ... is this the correct apporach or is there an easier way?
Thanks!
I just cant get it to work, this is my code:
<asp:UpdatePanel ID="UP_ExportInvoices" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:DropDownList ID="DDL_ExportFileDownLoad" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="DDL_ExportFileDownLoad_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
I was thinking that if the UpdateMode is set to Always, that the content is always updated? I also have that button (asp:ImageButton) which resides outisde this UpdatePanel. I tried adding a Trigger fpr that button, but it did not work. What am I making wrong. So far, im only thrwoing exceptions or the dropdown is not updated.
Thanks :)
If you are creating the file in the same page, then just append the file name to the dropdown. Can you do this trick in your application?
Does you button posts back the page? If yes, then you need to rebind the drop-down again after you create the file in button click handler.
If button makes partial post-back (say it is placed within UpdatePanel) to the server then above will be still applicable but dropdown should also be in UpdatePanel.
You need to ensure that the Button is a trigger for the Update Panel, or is a child within it.
Here is a full explanation:
http://www.asp.net/ajax/tutorials/understanding-asp-net-ajax-updatepanel-triggers
You need to place the button within the UpdatePanel. This will cause a partial postback and the dropdown should re-bind, showing the new item. Alternatively you can include JavaScript in your page which adds the new item to the dropdown list on the client-side, however this can sometimes cause problems with ASP's automatic event validation.

ASP.NET Fileupload and AJAX

I have a little problem with the FileUpload and uploadpanels.
As most of you probably knows you cannot use the asp:FileUpload control without forcing a postback. At least not what I know of, let me know if I am wrong.
Now my problem is:
I have a usercontrol with a FileUpload and a button that says "Upload". This UserControl is loaded into a UpdatePanel.
Now I want to register to the upload button inside the usercontrol as a postback trigger.
Is there any way to do this?
Does anyone know of a way to make fileuploads without postbacks?
Best Regards
The real napster
Solved this issue
If anyone meets this challenge it can be solved by doing this in your UserControl
ScriptManager sman = ScriptManager.GetCurrent(Page);
sman.RegisterPostBackControl(btn_addDocument);
You need to add a trigger to your UpdatePanel control to force the button that submits the page to perform a full postback. An example would be:
<triggers>
<asp:postbacktrigger controlid="btnSave" />
</triggers>

ASP Tabpanel postback only on one tab

I have a tabpanel with a calendar control on the 4th tab but when I select a date, the postback causes the tabpanel to return to the first tab instead of the 4th that it came from.
Is there a way to get it to return to the tab that the calendar control is on and not revert back to the first tab ?
I know setting autoPostback to true on the TabContainer will do this but that means it reloads on every tab change not just the one I want.
Any ideas ?
Wrapping the contents of the fourth tab in an UpdatePanel control should do the trick.
<ajaxToolkit:TabPanel runat="server" ID="tabCS" HeaderText="Country Settings">
<ContentTemplate>
<asp:UpdatePanel runat="server" ID="upCountry" UpdateMode="Conditional">
<ContentTemplate>
... content and calendar
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</ajaxToolkit:TabPanel>
Here is a best practice that I've found.
Unless other tabs in the tab panel need to be updated only put the contents of each panel in an update panel. If you need to update other panels you can call the method programmatically to update them.
There are two good reasons for this:
1.) By putting update panels in the tabs you will have fewer bits to get back from the server.
2.) Calling the update methods programmatically makes you more aware of what it is you are providing the end user and you won't forget to update the data.
Remember that if you use multiple panels to change the update mode from always to conditional so that only the relevant information is updated on the client.
Also if you want to put the entire tab panel control into the update panel you may need to add any formatting that is done to a CSS file since my experience is that it fails to retain the default formatting with it updates.
If you need more info or a code sample just message me.
Andrew

Resources