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.
Related
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.
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'
Basically, I have created a custom control that uses an UpdatePanel, and as I understand it I need to use a ScriptManagerProxy to make it work ( since there should only be one ScriptManager per page, and is is declared in my .aspx page ).So, how do you use this beastie, is it just a matter of adding:
<asp:ScriptManagerProxy ID="ScriptManagerProxy3" runat="server">
</asp:ScriptManagerProxy>
to your control, or is there more to it?
Could anyone please post a link to a good tutorial/example set? I tried googling for this, but I didn't find anything useful...
Your control does not require a ScriptManagerProxy to work. You would only need a ScriptManagerProxy if you needed to add a ServiceReference or ScriptReference in your control. The ScriptManagerProxy allows you to do this without having to have knowledge about the page that is going to host your control. When the page is rendered, the properties of the ScriptManagerProxy controls are merged with those of the ScriptManager control on the host page.
I have an interesting problem when using partial page update in asp.net with scriptmanager and a update panel.
My scenario looks like this: I'm using the tab control from the ajax toolkit. I also implemented this control using lazy loading, so that when the page is loaded only the current tab gets loaded all the other tabs don't get rendered, because Im using an UpdatePanel (on a .ascx control) on each of these tabs and when a tab gets selected the updatepanel makes a async postback to load the content for a selected tab.
On one of my tabs Im using a combobox control from obout.com, and it doesn't work.
Now I know why it doesn't work. It doesn't work because the control is shown via a partial page refresh, but to correctly display the control it has to do some "magic" that is - register some .css and .js includes on the page (in the head I guess)....but because I load this control via async page refresh...it can't do these stuff.
What kind of workarround do you suggest?
Thanks!
Assuming you have done partial ajax updates in asp.net before, then you simply need to register a client block with the ScriptManager for when the partial update is triggered.
Without knowing your problem space, it's difficult to paste specific code for you, so instead I'll just suggest you read this and then ask more questions if you have them...
http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerclientscriptblock.aspx
BTW, if you're dynamically creating the controls as well as partially updating them, then you will also need to be very careful of your viewstate. This is a can of worms, so hopefully you are not and won't have to worry about it.
As I suspected you have to manually register the needed scripts for ajax controls to work in such a manner.
For example here is the solution for telerik controls:
http://www.telerik.com/help/aspnet-ajax/troubleshooting.html
Here is a solution using devexpress controls:
protected void Page_Load(object sender, EventArgs e)
{
DevExpress.Web.ASPxClasses.ASPxWebControl.RegisterBaseScript(this);
}
I didn't found a solution for obout.com controls.
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?