UpdatePanel and UpdateProgress not working - asp.net

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.

Related

is posible to excute codebehind Event first while dropdown change

I have code like
<asp:DropDownList ID="SiteIDDropdownList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="SiteIDDropdownList_OnSelectedIndexChanged" onChange="javascript:markItUpApply();">
</asp:DropDownList>
Here I need fire first "OnSelectedIndexChanged" then "onChange"
is It possible?
"onChange" is a client side event whereas "OnSelectedIndexChanged" is a server side asp.net event, there is no way to fire these in a different order.
Try moving the code from onChanged into the OnSelectedIndexChanged event, of course you will need to convert it to .net code
You could remove the onchange attribute and register a startup script that will fire after the postback has completed which i think in effect will work just as you want.
In your OnSelectedIndexChanged Event you can use.
Page.ClientScript.RegisterStartupScript(this.GetType(), "testScript", "markItUpApply();", true);
EDIT:
In case you have update panel in the page then use this code
ScriptManager.RegisterStartupScript(this, GetType(), "testScript", "markItUpApply();", true);
hope this helps.
Well the case is that both are events and will fire when dropdown list onselected. But if you want to delay your codebehind call you can give this a try:
System.Threading.Thread.Sleep(2000);
But it will give you a delay for 2 sec and its not the best practices at all.

Button not processing onClick method

I have a button on an ascx control that calls a method on the onClick event:
<asp:Button id="bUpdateText" onClick="FUpdate" ValidationGroup="Update" CausesValidation="False" Text="Update" cssclass="button" runat="server" />
Normally I use this control on it's own page and the button works. This time round however, I am loading this control into a Div that is present on the home page of my site (that way I can show the contents with a little bit of JQuery). However, when I bring the control in this way, the onClick event doesn't fire and I am not sure what could cause that.
Sorry I don't have any code sample but the nature of the site makes it difficult to provide any that would make sense.
In short, what would stop this event firing now?
p.s I have tried adding validation groups to all other buttons and validation controls on the page and there is only ONE form present on the page.
EDIT: I have only just added the validation stuff in to see if that does anything. By default it has been like this and still didn't work:
<asp:Button id="bUpdateText" onClick="FUpdate" Text="Update" cssclass="button" runat="server" />
As mentioned as well, this works when I use this control on it's own page (loaded directly into Default.aspx) so I don't think the case of onClick matters.
EDIT2: I have just noticed that when I click this button, other validation controls on my page are being triggered even though they have their own DIFFERENT validation group?! Taking these controls out doesn't help though.
Thanks.
I have found out what is causing the issue.
This control that I am now including is called on the Page_Finalize() and I am guessing that by this point the viewstate has forgotten it needs to do anything. Loading this control on the page load sorts it out.
Thanks for looking.
To start, if you set the 'causesValidation' property to false, you do not need a validation group.
Additionally, I believe that ASP cares about case when dealing with the OnClick command.
i.e. it should be OnClick not onClick
Yeah, annoying and small, but that might be your problem
You can use Firebug to see what happen in Update validationGroup. it looks like your page execute only client-side button click because of Update validationGroup.

gridview delete command within updatepanel, and separate __doPostback() functionality

I have a gridview within an updatepanel, the rows have a delete button which removes that row.
Elsewhere, I run code to insert a row. Following this insert I run __doPostback() with the ID of the updatepanel, then in the updatepanel's load() event I call databind() on the gridview.
As soon as I implement the __doPostback() and databind, the inbuilt gridview delete stops working! :( The actual refresh/databind when adding the row works well.
How can I overcome this? I guess something may be awry in that when clicking on the delete button, the databind is conflicting with the inbuild delete/refresh functionality?
Thanks!
EDIT: Apologies if the question isn't described well...
Essentially, I wish to have a gridview with built-in delete functionality through the datasource and command column etc. inside of an updatepanel. I also want to update this panel seperately, but when I put in this separate update code (gridview.databind in the updatepanel.load) it breaks the standard delete functionality. Hope that is clear :)
You've tried put the UpdatePanelMode as Conditional and use UpdatePanel.Update() besides the ClientScript.RegisterStartupScript during your insertion block ?
I believe the problem is that the event is inside of the GridView and you can't access them as easily as you can with something like a Button. To register the GridView to make the Async events you need to attach it to the ScriptManager.
To do this you use the RegisterAsyncpostBackControl method.
Here is a general idea of how to do it.
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server">
<%-- your fields, etc --%>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
In your code behind you do
protected void Page_Load()
{
ScriptManager1.RegisterAsyncPostBackControl(GridView1);
}
It's been a while since I've done this but I believe this will allow the GridView to function as you'd expect, except you don't need the extra DataBind() I don't believe in this case.
You can also set the UpdatePanel to Conditional and fire an UpdatePanel1.Update() on top of this as Jeison suggested.
You can find some added details at http://msdn.microsoft.com/en-us/library/bb386452.aspx
If you still have trouble, let us know what happened.
It seems like you calling DataBind() of GridView every time the UpdatePanel load after the insert button click, it reload the data before delete reaches the DataSource.
EDIT
If so, you can add boolean eventArgument in __doPostBack(updatePanelId, "true"). And using this you could add a condition in your updatepanel load event like
if(this.updatepanel1.Page.Request.Params["__EVENTARGUMENT"] == "true"]
this.gridview.databind()
Hope this will resolve the issue.

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 AJAX Modal Popup Extender - Cancel button doesn't work after postback

The panel which my modal popup extender "shows" has an update panel within it, to handle valiation.
However, after postback, the close button doesn't seem to work. It just closes the panel butit leaves the modalBackground [greyed out].
<ajaxToolkit:ModalPopupExtender
ID="ActivateModalDefault"
runat="server"
TargetControlID="btnRegister"
PopupControlID="pnlShowModal"
CancelControlID="CancelLinkButtonDefaultPage"
BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>
Any ideas on why this would be happening?
Doesn't sound like normal behavior if it's been implemented correctly. Do you have more to add to this snippet?
The issue was, the CancelLinkButton was wired up in jQuery as well, thus causing the very very strange behavior

Resources