AsyncFileUpload, can't refresh page after upload is completed - c#

I have an Ajax AsyncFileUpload on one of my pages (inside a update panel). The control works, however I want the page to reload after the upload is complete. I tried a Response.Redirect in the code behind for the OnUploadedComplete method and a location.reload(true) in the OnClientUploadComplete. Both result in javascript alert of `Server Response Error: 'Unknown Server error'
Do you want to see the response page?` and the page doesn't refresh.
Has anyone been able to do a full page refresh after the upload has completed?
Edit: I mistakenly said the AsyncFileUpload is in a control panel, I meant to say update panel.

Use asp:FileUpload control and register it as postback control with Scriptmanager's RegisterPostBackControl method. Or add postback trigger entry for this FileUpload to Triggers collection of UpdatePanel

This control panel that you told. Is this a UpdatePanel? If it is, you can try an upd.Update(); to refresh the panel.

Becareful, if you have Response on your backside you may be ending your page's life cycle right there. This is just a guess. Check to make sure that your code is even reaching the intended point. Look for things like Response.End which will will prevent anything thereafter from executing.

Related

How to get updated page information through C# WebBrowser when updatePanel AJAX event happens?

I am automating a scenario in WPF using WebBrowser. Code snippet is as follows
string id = paginationControlProcessing[1].PageCtrl.id;
webDoc.GetElementById(id).GotFocus += new HtmlElementEventHandler(wb_OnGotFocus_PaginationControls);
webDoc.GetElementById(id).Focus();
webDoc.GetElementById(id).RaiseEvent("onChange");
webDoc.InvokeScript("__doPostBack", new object[] { "ctl00$ContentPlaceHolder1$pgControl$nextPageLink", "" });
When the page changes through pagination control, I am able to hit the event handler for focus change. Problem is happening when pagination controls are hit where I am not able to retrieve the data for 2nd and 3rd page.
I can do the page navigation and it works in the WebBrowser control. Data is also updated in the table to which these ASP.net AJAX controls are attached. In the event handler, when I look into the content of object WebBrowser1, it does not contain the content of new data that appears in the UpdatePanel control. Data for the control when 2 and 3 are clicked comes through UpdatePanel ASP.Net control.
What event can be used to capture the data coming for UpdatePanel control from server?
One way to achieve the task specified above is to use FiddlerCore but one has to be aware of the gotchas related to certificate generation in fiddlercore since ASP Panel controls use HTTPS mostly. All interactions on Panel control of ASP generates partial POST requests that result in partial responses with updatePanel contents. It does not update the page source nor there is any automatic redirection happening. Once a page is loaded, any interactions happening in Panel controls must be handled by application driving the automation and it cannot be done through WebBrowser as it is unaware of any update in the page. Be aware that UpdatePanel responses can also update the __VIEWSTATE and other hidden values. Use fiddler to capture responses and then re create them using custom processing through HttpWebRequest. HttpClient is not suitable for most cases since it needs a separate thread to handle async task and then it can become messy to handle events passing between UI, WebBrowser, Fiddler thread and HttpClient tread.
A good place to get help on usage of FiddlerCore is at the Google group for Fiddler.

find a client Side event of radGrid or Div that accure before any postback in page

i have a customized radgrid in my page that some script have set for ongriddestroyed event. my script get all controls and their value in page and sent them with Ajax to server side. consider a buton on page too that cause a postback, but i want my javascript code fire before any post back in page . i tryed window.onbeforeunload , it works fine till i use radajaxpanel or a update panel on page...
is there any javascript event that fire before any post back that i can set for my radGrid or its parent that is a div element?
thanks
The ASP.Net Ajax RadAjaxManager component of the telerik control suite
provides a client side event handler called OnRequestStart.
OnRequestStart is called when an ajax request is started by
An control configured in RadAjaxManager
A control within a RadAjaxPanel
Client side ajaxRequest() call
So, the OnRequestStart handler is a good place to execute
a client side script before an AJAX request is executed (e.g. triggered by an control inside an RadAjaxPanel).
You can also cancel the AJAX request in the OnRequestStart handler.
For more information see the telerik online help on this topic.
You will also find an example there.

More detailed explanation about GetPostBackEventReference method

I understand that this will causes a page reload (partial or full, depending on how your UpdatePanels are set up)
But,
where in the code I should put it (client or server side)?
which control should I send to the method? Is it must be inside the UpdatePanel?
does this method work only for controls inside update panels?
must the control have a postback capability?
what is the engine behind this? How does this method work, so I could use it properly.
Thanks.
The function call returns a string of executable JavaScript, which you need to write to the client somewhere in your response.
Typically, you're sending your Page (this/Me) unless you have a control that you specifically want to handle the postback (ie, that implements IPostBackEventHandler)
GetPostBackEventReference is not related to UpdatePanels; if you have one, it will handle the postback.
No (see #2)
This makes a postback to the page. If you want it to raise an event when it posts back, you need to implement IPostBackEventHandler, either on your page or on one of your controls.
http://msdn.microsoft.com/en-us/library/ms153112.aspx

Multiple UpdatePanels and onload

I have a page that has 2 dynamically loaded user controls each within it's own update panel. On load of the user controls, I execute javascript that updates the css of the table cells.
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "Load_RunScript()", true);
Both user controls have a button each that causes a postback and on the server side executes JS for making some change. The issue I run into is when I click on the button on one of the user control (Say UCtlA), the postback causes the user controls to be reloaded dynamically which executes the onload script in UCtlB as well causing the page to perform slow.
Since the UCs are in UpdatePanels, my understanding was the UI should not be re-rendered on postbacks. Why is this happening and what is the solution?
UpdatePanels cause a Postback similar to the Page postback. To avoid unnecessary work in Pageload check the ScriptManager.IsInAsyncPostback property to detect the UpdatePanel Postback. Only the controls in the UpdatePanel causing the Postback should update their GUI.
Add the UpdateMode="Conditional" property and possibly ChildrenAsTriggers="false"
http://weblogs.asp.net/alessandro/archive/2008/01/30/reducing-updatepanel-bloat-by-utilizing-updatemode-quot-conditional-quot-and-childrenastriggers-quot-false-quot.aspx
Honestly I would say steer clear of UpdatePanels because they are dogs especially nested UpdatePanels.

c# Ajax Lazy Loading

I need to populate 4 GridViews on an aspx page, but I only bind a datatable to one of them on page load. I need to pupulate the other 3 after page load.
does anyone know the best way to do this using ajax ?
Currently I'm using javascript to __doPostBack on a button that pupulates the 3 GridViews but unfortunately this forces a full page load even when using an update panel. I need the page to load, and then populate the GridViews as the datatables are returned.
any suggestions would be much apreciated.
The way you are doing it should work ok, although using jquery to populate a div via the $("#targetDiv").load("contentUrl"); function may be a cleaner way to do it. Anyway, in order to get your current implementation working, there could be a few things you want to look at:
I assume EnablePartialRendering is true on your ScriptManager (always worth checking!).
Make sure the eventTarget for the __dopostback call is set up as an async trigger for your update panels or that it is inside the UpdatePanel if you are only using one UpdatePanel. (See here for details)
Try returning false from the javascript code that executes in the onclick event handler if you have attached this to a button, to make sure the form is not being submitted normally by your browser when you click the button.
If I understand the question properly, you want the data to load after the page is in the browser. If this is the case, then you can fire an event with JavaScript when the page loads on the client.
One method I've used is to put a hidden (with CSS, not any property) button on the page and 'clicking' it with javascript. The event of the button click event will need to be wired in the page's code. Also the button would have to be in an update panel that either contains the grids you want to be bound or has the appropriate triggers to cause them to reload.
You might look at JQuery to get manage when this code gets fired. The $(document).ready(function(){ /* Your code here... */ }); method will fire after the entire DOM is available, which is faster than waiting on the entire page to load (images and so forth).

Categories

Resources