UpdatePanel with UploadFile control doesnt work well - c#

I've three images. I use javascript to mark which one is selected. After user clicks on one I change its class to active. its <li><a>. Now when I wasn't using updatepanel after form post I could see from code behind which element is active and it was correct. After adding updatePanel which contains entire form after postback which should refresh content of updatePanel value is wrong and active is always set to default first <a>. Whats more in this updatePanel there is UploadFile control which doesn't work well because it always has HasFile value to false even though I choose file.
Thanks You for any hints

Your form must be a full postback. You have to add a Trigger for the Full postback, if your FileUpload control is in the update panel.
Alternatively if you want to upload Asynchronously , you could try AJAX AsyncFileUpload control
http://asp.net-informations.com/ajax/ajax-AsyncFileUpload.htm

This is a well known problem, please take a look into the following article:
http://geekswithblogs.net/ranganh/archive/2008/04/01/file-upload-in-updatepanel-asp.net-ajax.aspx

Related

asp FileUpload in content page not working due to updatepanel in master page

I have a master page where an update panel contains the main placeholder of the content pages.
Inside one of the content pages I need to disable the update panel in any way since I have a form with asp:fileupload control that is always returning null due to the update panel.
How can I overcome this issue?
Place your fileuploader and submit button in another update panel and add a post back trigger for this update panel.
On page load of content page, try to get the update panel of master page using FindControl method and then attach your file upload as a post pack trigger to it dynamically.
That may work
I've got a bad news for you.!
Have a look at this
http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx
The following ASP.NET controls are not compatible with partial-page updates, and are therefore not supported inside an UpdatePanel control:
TreeView and Menu controls.
Web Parts controls. For more information, see ASP.NET Web Parts Controls.
FileUpload controls when they are used to upload files as part of an asynchronous postback.
GridView and DetailsView controls when their EnableSortingAndPagingCallbacks property is set to true. The default is false.
Login, PasswordRecovery, ChangePassword, and CreateUserWizard controls
whose contents have not been converted to editable templates.
The Substitution control.
Validation controls, which includes the BaseCompareValidator, BaseValidator, CompareValidator, CustomValidator, RangeValidator, RegularExpressionValidator, RequiredFieldValidator, and ValidationSummary control.
Solution :
You may want to use Ajax FileUpload using Jquery in place of update Panel. Remember, Open source is always a better option. :)

IEWC Treeview refreshing to top of page on click

I am using an IEWC webcontrol in ASPX/C# page and whenever a treeview element is clicked, it will refresh to the top of the page. Is there any way to stop this?
It now works fine in IE with the addition of Autopostback and Viewstate set to True. Just not in Chrome.
(Note: I am well aware that IE web controls were never meant to work 100% outside IE)
This was fixed by adding in a piece of jQUery that searches for the element's parent ID and removes the HREF on the nodes.
Alternatively, you can set a session parameter that remembers the scrollX and re-set this on page load

Dynamic Drop Down List ASP.net

How can I create a dynamic drop down list without using AutoPostBack. I ask because I just want to change the value of what the second drop down list displays and then the user clicks a button and it submits. But If I use AutoPostBack then it postbacks to page and runs code that shouldn't be run until that final box has been selected. (I use Postback in the other part of my program so using !IsPostBack isnt a option.) I looked at Javascript but ASP generates all of its controls names at runtime. What can I do? I have looked at the Ajax CascadingDropDown control but my problem with that is it contained in a XML file or a Database, I need this to be contained inside my Page. Any Ideas?
You can use the CascadingDropDown control from the AJAX Control Toolkit
Maybe this example will help? It's part of the ASP.NET AJAX Control Toolkit available here.
You can use AJAX to get the values for the second drop down list, based on the selected value of the first. Add a onchange event handler on the client-side to the first drop down list that makes the AJAX call and fills the second on success.

#OutputCache problem in a UserControl

I have a user control with this OutputCache:
<%# OutputCache Duration="86400" VaryByControl="LnkBtnTopVanzari" %>
Where VaryByControl is the id of a link button i use to switch the active view of a multiView contained in an updatePanel.
The problem is that when i press that link button, the page does a full post back and the view is not switched.
If i remove the outputCache directive, all works great (pressing the link button the correct view is shown via ajax).
Do you know where i am wrong?
Thanks.
The VaryByControl parameter is used to vary depending on the value of the control which you specify. As the value of the link button will always be the same, the cache is not varied.
I believe this is intended to be used for controls such as dropdown lists, where it is feasible for the output to be different based on the selected value in the list.
You may want to try using VaryByParam and changing your link button to a hyperlink, specifying the view as a query parameter, or trying out VaryByCustom. Otherwise possibly you could possibly split the content of your views into separate user controls which are themselves output cached, leaving the multiview and your link button outside any caching.

Using Page.IsPostback Within a User Control Wrapped in an Update Panel

I have a main page into which i load a user control with a grid and add/edit link buttons.
If I bind the grid by setting the datasource and calling the databind() method in the page load event then it sets properly. However, I want to keep the selected row between postbacks, so I wrap the bind code in "if (!Page.IsPostBack) {}" as usual. My problem is the page load always registers it as a postback and my code never runs.
I am using the 2.0 framework, and my grid is an 2008.1 Infragistics for the 2.0 framework.
I thinking this must be something simple.... or hoping anyway!
Thanks in advance
If you place your control into an UpdatePanel, then you should check for Page.IsCallback instead of Page.IsPostBack.
The two ways I found round this were:
to load the user controls when the page is first loaded and then hide them until user selected what they need to see.
to load a new page into an iframe on the main page allowing it to have its own page control meaning when its loaded in at first its not a postback.
Not the greatest, but gets by.
Thanks for the help.
I have mixed feelings about necroing a thread this old, but the question is still relevant, and there weren't any great solutions offered, so though I would add what I recently did to solve the same issue:
I had a similar problem with a site I was building. My solution was to add a method to the user control called "OnFirstLoad" that does all of the stuff I would have wrapped in an "if not Page.IsPostback" block. I then call the "OnFirstLoad" method from the hosting page the first time the control is loaded into the control tree. This way the control itself doesn't have to worry about whether or not this is a postback, and the main page can initialize it as needed.

Categories

Resources