ASP.NET - reload a dropdown? - asp.net

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.

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>

Refresh a control on the master page after postback

What i am trying to do here is to show a couple of validation messages in form of a bulletlist, so i have a Div on my master page containing a asp:bulletlist. Like this:
<div>
<asp:BulletedList ID="blstValidationErrorMessage" runat="server" BulletStyle="Disc">
</asp:BulletedList>
</div>
When i then click the Save button from any of my pages (inside the main contentPlaceHolder) i create a list of messages and give this list as datasouce like this:
blstValidationErrorMessage.DataSource = validationMessageCollection;
blstValidationErrorMessage.DataBind();
The save button is located inside an updatepanel:
asp:UpdatePanel runat="server" ID="UpdatePanel" ChildrenAsTriggers="true" UpdateMode="Conditional">
Nothing happens, i can see that the datasource of the bulletlist contains X items, the problems must arise because the Save button is inside an update panel and the elements outside this updatepanel (master page controls for example) is not refreshed.
So my question is, how do i make the bulletlist refresh after the postback?
Thanks in advance.
If your button is inside an UpdatePanel, you should place your BulletedList control inside an UpdatePanel too.
You can place an UpdatePanel surrounding the BulletedList in the MasterPage file. Set "UpdateMode" to "Conditional" then call the Update method of the UpdatePanel to refresh only when needed ('save button' click for example).
The Save button will only update the contents of the UpdatePanel you placed it in. Here's what I recommend doing:
Move the SaveButton outside of the UpdatePanel. Where you put it I'll leave up to you.
Put your validation div inside another UpdatePanel. Call it ValidationUpdatePanel
Add your SaveButton as an AsyncPostbackTrigger for both update panels. Since you may have each UpdatePanel separated into different controls/pages, you'll probably want to do this in the code-behind programmatically.

UpdatePanel and UpdateProgress not working

If I use: OnSelectedIndexChanged like this:
<asp:DropDownList ID="ddl1" AutoPostBack="true" OnSelectedIndexChanged="Test_SelectedIndexChanged" runat="server"></asp:DropDownList>
UpdatePanel and UpdateProgress work correctly, meaning it shows my little gif etc.
However as soon as I change this to call javascript code, like this:
<asp:DropDownList ID="ddl1" AutoPostBack="true" onchange="selectValues()" runat="server"></asp:DropDownList>
It stops working. The progress doesn't show up. Now, before anyone asks why do I this, it's because I need to call some scripting into the managed code. It has to do with silverlight.
Does anyone have solution to this problem?
if your update panel doesn't refresh, the updateprogress control will not operate. if you try to update something without calling the update of the updatepanel (ie using your own JS) the updateprogress will not work.
I would guess it's because the progress is hooked up to show when the UpdatePanel is updated.
Does your second drop down trigger the update panel when you select from the list?
You may have to add a OnSelectedIndexChanged event to your drop down that does nothing to trigger the update panel.
You could add some javascript in yout SelectValues() function to show the progress panel, i believe it is simply a div with an image that you could change the css using javascript to visible.
Hope that helps!
I think your javascript is returning false value. So the server side event of dropdown selectedindex change event does not fire as it it not postback whole page.

Trying to self contain pop ups which use the AjaxToolkit ModalPopUpExtender

I have 3 different kinds of ajax popups that need to exist across my site. I was hoping that I could simply create a user control for each one and place the panel and modal popup extender inside each one but this doesn't seem to be working. Has anyone tried this before or do you have a recommendation as to how I can avoid duplicate code for each pop up on different pages? Thanks!
Ah I figured out my issue with the User Control I believe.
The ModalPopUpExtender requires the TargetID property to be set otherwise an error occurs. Since this is sitting in a UserControl I just created a dummy link button that doesn't do anything and I set the property visible to false.
<asp:LinkButton ID="lnkBlank" runat="server" Visible="false" />
<asp:Panel ID="plContainer" style="display: none;" runat="server">
Hello?
</asp:Panel>
<cc1:ModalPopupExtender ID="mpe" runat="server"
BehaviorID="test"
TargetControlID="lnkBlank"
PopupControlID="plContainer" />
Apparently it doesn't appreciate that and the moment I set the visible property to true it started working. Not sure what the reasoning is for a TargetID since, I would think, most pop ups could be called from multiple links about the page. Perhaps I'm still not entirely clear on how this control is supposed to be used.
One option would be to write the popups in a asp.net user control (a .ascx page) and include that on the pages you need the popups. Have a public method in the ascx page that will show the popup, and call it from the parent page when you need to. If you already have a script manager on the parent page, you can't have a second one in the ascx page, but other then that there shouldn't be anything that would stop this from working. Hope this helps!
edit: here's what my modal popup extender control looks like...
<cc1:ModalPopupExtender
ID="mpeClassroom"
BackgroundCssCLass="modalBackground"
runat="server"
CancelControlID="lbClose"
OnOkScript="onOk()"
TargetControlID="Button1"
PopupControlID="pnlClassroom">
</cc1:ModalPopupExtender>
in my code behind page, my method just calls mpeClassroom.Show();
The problem with hidden link as TrgetControlID is that; when u set its visibility as false, server doesn't render it as well. PopExtender then cannot find control on the page.
Instead of setting its visibility to false, try to apply a style with display:none. This should work !

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