AsyncFileUpload and GridView - asp.net

I've a little problem.
I have in the same page an AsyncFileUpload and a gridview.
How do I update this gridview immediatly after it has been done upload with AsyncFileUpload?
Thanks

I have a solution that i am using, maybe there are better ones but at least it's working:
On your aspx page create a div like:
<div style="visibility: hidden;">
<asp:Button ID="btnHidden" runat="server" OnClick="btnHidden_Click" Text="Button" />
</div>
On your AsyncFileUpload's OnUploadedComplete event write a code that stores the needed informations about the uploaded file in Session variables (since AsyncFileUpload dont have a viewstate).
On your AsyncFileUpload's OnClientUploadComplete place a Javascript function that click's the hidden button and in the codebehind the hidden button's click method is binding your gridview and clearing the session. Thats all! :)
ps.: wrap around your gridview with an updatepanel and your page wont blink

Related

ASP.NET webform Fileupload inside an ascx which is inside an updatepanel in the aspx

here is some code in my page :
<asp:UpdatePanel ID="UpdatePanelEQSelector" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc12:EQSelector ID="custEQSelector" OnEqChange="custEQSelector_OnEqChange" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Inside my user Control, I'm asked to add a fileuploader.
After coding it simply, I tested and my fileuploader is always empty.
I've searched a while and discovered that it was a normal behavior.
The solution to make it work is to add a PostBackTrigger for the updatePanel.
When I tested it in my aspx page, I achieved to do it and my fileUploader had the file.
Then I tried to add it dynamically (to finally do it in my control), it worked with that :
PostBackTrigger trigger = new PostBackTrigger();
trigger.ControlID = this.btnTest.ID;
this._UpdatePanelEQSelector.Triggers.Add(trigger);
But I can't manage to make this code work in my control (I passed my updatePanel as a parameter to my control set in Load, the fileUpload is always empty)
Do you see a solution ?
Thanks
Does it postback, but leaves the control empty? or is it not posting back at all. If it's not posting back at all I'd add this
ScriptManager.GetCurrent(this).RegisterPostBackControl(btnTest);
to the page_load of the user control.
If it is posting back, but the control is empty, then I'd wager there is probably some dodgy html somewhere on the page and the values are getting lost.

asp.net button doesn't cause post back when clicked repeatedly

If I click a button very fast after page load, the post back won't be fired. The following example illustrates this (you have to click the button twice and very fast):
<form id="form1" runat="server">
<div>
<span id="submitText"></span>
<br />
<asp:Button ID="btnSubmitTest" runat="server" Text="Button"
OnClientClick="document.getElementById('submitText').innerText='you should not see this after postback';" />
</div>
</form>
The submitText, the button set's before firing, should not be visible after the postback. But if you click at the button very fast, it happens, that the event doesn't fire.
I think, that the page isn't loaded completely at this moment. Or is there any other reason for that behaviour? How do you handle this?
You will loose all javascript dom updates on postback. What you have explained sounds correct... you see the client click event fire just before page posts back and the dom is reset.
Try the same exercise by populating a textbox. In that instance the value will maintain as the textbox relies on viewstate. You could put a runat="server" on the span, but I believe you would have to manually assign the value to viewstate as I don't believe htmlgenericcontrols automatically utilize viewstate.

UpdatePanel update without trigger button

I have an UpdatePanel with ContentTemplate specified. When page loads, user can do some AJAX work in other part of the page. Then, after that work is finished, I would like to update only content inside UpdatePanel, but without pressing any buttons etc. I should be done automatically using JavaScript when previously started AJAX work finishes. How to do it without manual clicking on the trigger button?
EDIT:
Ok, I've followed that _doPostBack rule, and whole page is posted.
<asp:UpdatePanel ID="panelAttachments" runat="server">
<ContentTemplate>
........
</ContentTemplate>
</asp:UpdatePanel>
<input type="text" name="test" onchange="__doPostBack('<%=panelAttachments.UniqueID %>',''); return false;" />
</td>
Thanks, Pawel
To refresh an update panel from javascript:
__doPostBack(updatePanelUniqueID,'');
The first parameter is the UniqueID (not CientID) of the UpdatePanel.The 2nd parameter is optional arguments you can pass which will be available to your server code. Both are stored in hidden form fields by ASP.NET, you can access them in codebehind:
Request.Form["__EVENTTARGET"];
Request.Form["__EVENTARGUMENT"];
But if you just want to refresh a panel and don't need to pass any additional info from the client, you can ignore then 2nd argument.
If you look at the HTML generated by ASP.NET for an async postback control, you'll see it's exactly this.

HTML buttons: Code-behind operation

Earlier, I had a button control on my web page. but now I changed it to a CSS button suting my needs. Before this, the button control was performing code-behind operation but now I switched to this CSS button.
Delete profile
How can I accomplish the same code-behind process now?
You can change the anchor to be a server side control (turning it to a HtmlAnchor control) and use the ServerClick event:
Delete profile
To keep it simple, you could use a linkbutton and get the server side click event
<asp:LinkButton ID="lb1" runat="server" onclick="lb1_Click" CssClass="cssClass" />

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.

Resources