How to stop full page postback in asp.net ? - c#

I have a fileupload control in Updatepanel. It only works when i register <asp:PostBackTrigger ControlID="btnAddPersonalInformation" /> in triggers but the problem is that it refreshes whole page which I don't want to. How to stop this full page upload. I also used AsyncPostBackTrigger but that also doesn't work i.e. doesn't upload file so the only way is PostBackTrigger but that refreshes whole page.

Use a ScriptManager along with the update panel control. ScriptManager should be placed before the UpdatePanel. You can refer MSDN documentation.

Related

AsynchPostBackTrigger still refreshes whole page every OTHER time

I've just implemented a small UpdatePanel with a button outside the panel that modifies the controls within it. Per instructions here and here I have set up a trigger on Page_Load that looks like this...
UpdatePanel1.Triggers.Add(item: new AsyncPostBackTrigger
{
ControlID = Button1.UniqueID
});
...in order to allow the button click event to update the panel asynchronously (it was refreshing the whole page before). However, now it works asynch the first time, but every other click after that triggers a whole page refresh. I'm pretty confused by that one. Can anyone spot what's wrong? (Edit: To clarify, the following represents the refresh results of a series of clicks starting after page load: Asynch (good), Whole Page (bad), Asynch, Whole Page, Asynch, Whole Page, etc...)
FYI the form is ASP.NET 4.0 and resides in a SharePoint 2013 visual web part, if that matters.
try scriptmanager EnablePartialRendering property like this
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableViewState="False" EnablePartialRendering="true"> </asp:ScriptManager>

How to Change label on Default page when user controls returns to page?

I made a web user control. After the code of user control is returned to the default page, then I want to retrieve some value of user control.
Like the following code...
<asp:Label ID="lblmaster" runat="server"></asp:Label>
<uc1:UserControl ID="WebUser" runat="server">
</uc1:UserControl>
The Label is visible only when the all the operations in user control are done. how this is possible??
You can use Ajax Extension controls - UpdatePanel and UpdateProgress. Place the Label into UpdateProgress and UserControl in UpdatePanel. For more info read MSDN article .
I would use the Session to store the details when moving from usercontrol to usercontrol

Fileupload inside Updatepanel which in Usercontrol?

i am doing Fileupload using asp.net 3.5 with asp.net ajax.In that i am using Usercontrol
MainPage.ascx Page:In this page i am using UpdatePanel inside Fileupload control.
Demo.aspx:In this page also i am using Updatepanel. i am drag MainPage.ascx usercontrol inside this UpdatePanel which is in Demo.aspx.
Question: When i drag the Mainpage.ascx Usercontrol on Demo.aspx . Here i am getting the Fileupload.HasFile is getting null .If anybody knows Plz.
Please do the needfull.
You need to add a PostBackTrigger for your UploadControl because it is inside an update panel. (Maybe you need an AsyncPostBackTrigger)
A standard fileupload control cannot be used in an ajax-postback. You could use an AsyncFileUpload control from the ASP.NET Ajax Control Toolkit. This control can send files in an ajax-postback and has some other options that you can see in the demo.
If you use the AsyncFileUpload, make sure to use the ToolkitScriptManager from the Ajax Control Toolkit instead of the default ScriptManager.

Asyncfileupload doesn't work in webusercontrol

I'm having a problem with a Webusercontrol that has an asyncfileupload control.
My websusercontrol is being loaded in a placeholder control that's wrapped by an updatepanel.Due to asyncpostback, I have to load and clear the placeholder's controls.
The webusercontrol works flawlessly, except the asyncfileupload, which doesn't want to upload at all. I can assure that the code is without error, because I used to have the webusercontrol running as an *.aspx site.
I guess that the problem is the fact that the control has to be cleared and reloaded with every asyncpostback ?
I think issues occur once you place your AsyncFileUpload control inside a dynamically-loaded custom user control.
I managed to get around this issue after reading this link
Basically, I placed a dummy AsyncFileUpload control on the parent .aspx page.
E.g. Default.aspx
<span style="display:none">
<asp:AsyncFileUpload ID="DummyAsyncFileUpload" runat="server" />
</span>
Note that the AsyncFileUpload control is hidden from users, but still visible to ASP.NET.
My theory is this:
In order to upload files, you have to post your form's content using a different encoding type (multipart/form-data).
When you place your AsyncFileUpload inside an UpdatePanel, ASP.NET for whatever reason, does not set the encoding type at all, and leaves it empty.
e.g. document.forms[0].enctype = ''
Thus, when you post your form, it does not know what to do with file upload.
By placing the dummy AsyncFileUpload on the Default.aspx page, ASP.NET detects the presence of the FileUpload control, and will set the encoding type accordingly.
e.g. document.forms[0].enctype = 'multipart/form-data'

How can I pass data from an aspx page to an ascx modal popup?

I'm fairly new to ASP.NET and trying to learn how things are done. I come from a C# background so the code-behind portion is easy, but thinking like a web developer is unfamiliar.
I have an aspx page that contains a grid of checkboxes. I have a button that is coded via a Button_Click event to collect a list of which rows are checked and create a session variable out of that list. The same button is referenced (via TargetControlID) by my ascx page's ModalPopupExtender which controls the panel on the ascx page.
When the button is clicked, the modal popup opens but the Button_Click event is never fired, so the modal doesn't get its session data.
Since the two pages are separate, I can't call the ModalPopupExtender from the aspx.cs code, I can't reach the list of checkboxes from the ascx.cs code, and I don't see a way to populate my session variable and then programmatically activate some other hidden button or control which will then open my modal popup.
Any thoughts?
All a usercontrol(.ascx) file is is a set of controls that you have grouped together to provide some reusable functionality. The controls defined in it are still added to the page's control collection (.aspx) durring the page lifecylce. The ModalPopupExtender uses javascript and dhtml to show and hide the controls in the usercontrol client-side. What you are seeing is that the click event is being handled client-side by the ModalPoupExtender and it is canceling the post-back to the server. This is the default behavior by design. You certainly can access the page's control collection from the code-behind of your usercontrol though because it is all part of the same control tree. Just use the FindControl(xxx) method of any control to search for the child of it you need.
After some research following DancesWithBamboo's answer, I figured out how to make it work.
An example reference to my ascx page within my aspx page:
<uc1:ChildPage ID="MyModalPage" runat="server" />
The aspx code-behind to grab and open the ModalPopupExtender (named modalPopup) would look like this:
AjaxControlToolkit.ModalPopupExtender mpe =
(AjaxControlToolkit.ModalPopupExtender)
MyModalPage.FindControl("modalPopup");
mpe.Show();
Sorry, but I'm confused. You can't call an ascx directly, so...
Is your modal code that you are calling from within the same page, like a hidden panel, etc;
Or is it another aspx page that you are calling on a click event?

Categories