Redirection from a Telerik Rad Window - asp.net

In an asp.net web application, I have a modal popup built with a Telerik Rad Window. In that popup there is a button which must do some action in its "code-behind" and then redirect the application to another page.
For the redirection I use the javascript command 'top.document.location.href = myPage' (sent to the browser from the code-behind with a ScriptManager.RegisterClientScriptBlock(...)).
This solves my problem but it is not very nice. When the button is pressed, this triggers the post-back. In the browser the popup is covered by a RadLoadingPanel which disapper when the post-back is finished. Then during a few seconds, nothing happens in the application and it is only after some time that the browser loads the new page.
The fact that nothing happens during a few second is not great since a user cannot know what the application is doing.
What can I do ? Is there a better way to do the redirection ? (I'm very new to javascript programming...).

Instead of just calling 'top.document.location.href = myPage', you can call a function that displays an overlay (e.g. show a RadAjaxLoadingPanel over the parent page body) and then set the new URL. See http://www.telerik.com/help/aspnet-ajax/ajxshowhideloadingpanel.html for info on how to show loading panels with JavaScript.
I think the delay after you set location.href is normal - the browser/server take some time to retrieve the new page HTML so the old page cannot go away instantly.

Related

Reason Page Reloaded

I am porting an application from ASP.NET 2 to ASP.NET 4.5
I have a page that creates a popup windows (Another .aspx page started with the javascript modalWin function).
When the popup is dismissed (using window.close()):
Under 4.5 the primary page refreshes
Under 2.0 it does not refresh.
This is a problem because it throws away all the data on the parent page.
How can I determine what it causing the parent page to refresh?
This is difficult for me to debug because I don't know where to set a break point to step thru code to figure out what it is doing. When I set a break point in the onload= function it just reports the call stack of the page starting the javascript.
I am new to visual studio so please use terminology and instructions that I can see on the screen.
The parent page invokes the popup page like this:
<button id="bbb" onclick="button_onclick(this)">Button</button>
The javascript looks like this:
function button_onclick(element) {
modalWin("popup.aspx", 300, 300);
}
When the user clicks the save button on the popup page this javascript runs:
function closeit() {
window.returnValue = true;
window.close();
}
I have dug into the change history of the code and previously the <button> button was a image button but the javascript that is invoked did not change.
"previously the button was a image button". You seem to mention this in passing almost, but here's your clue. An image with a client-side click event wouldn't cause a postback, because images never do that. Whereas a <button> element will, by default, cause a postback, because its default type is submit. You need to change that to button to prevent it.
<button type="button" id="bbb" onclick="button_onclick(this)">Button</button>
This is the crucial change, and is related to the way the web works in general, not to ASP.NET. The change of .NET Framework is a red herring. The problem does not occur because you changed frameworks, it's because you changed the code

How to close aspx page that is redirect from handler

I am in critical situation.
In my application I try to close opened window using javascript function.
function Close_Window() {
var myWin = window.open('', '_parent', '');
myWin.close();
}
this function is used in 3 aspx pages.
That page will open from mail means my application is used for sending Mail.
In that such as normal newsletter there will be three footer links like UnSubscribe,Forward A Friend,Change E-Mail address.
So on click of close button for above these three pages I had written that code.
The page will be opened from “ashx” file. And I try to close it using Javascript.
So close button is working when I direct click on the above three links.
But by right clicking on that I open it in new window or new tab close button is not working.
So please give me solution that how can I close aspx page using javascript or in code behind.
My purpose is page should be close any how by javascript or by code behind.
Note : I am opening that page using ashx handler.
If you want total control of opening and closing windows, keep the control and do not transfer the control to the browser. The behaviour of Html is well defined by W3C. The behaviour of new browser windows/tabs will vary between different browsers, and probably in the future.
Why do you open and close a page directly?
Probably you want to execute a GET request on the server to trigger some action. Take a look at the jQuery get method. So you can execute your request, without the need to open/close a new page.
If you want the user to make a choice, after clicking the link, I would work with a jQuery modal dialog. This pops up a dialog, but inside the current HTML page. Therefor you are in control of closing the dialog.
If you open a new window/tab the browser is in control, and the behaviour depends on the browser / user settings combination.

Dynamic web user control problem when browser's back button is clicked

I have an .aspx page in which I dynamically add web controls to a panel.
The problem is when I hit the browser's back buton, it's displayed a version of the page that no longer exists on the server-side, because the controls are dynamically added.
Let's say my aspx dynamically adds Control1. From there, I click a button that loads Control2.
At this moment, if I press the browser's back button, it will display the page with Control1, but Control1 no longer exists on the server-side, so if I interact with it, some erractic behaviour will occur. Any ideas on this?
Thank you very much.
Have you tried setting the client side to not cache pages - stick this in your page load:
Response.Cache.SetCacheability(HttpCacheing.NoCache)
(Think the syntax might be slightly off, but you should be able to figure it out)
Have you tried with removing temporary files and restarting browser. Your page might be cached in browser.

ASP.NET, Showing Loading message while Postback

I have an ASP.NET page which has an asp.net button control in it. When the user clicks on the button, the page will do some calculations and then close itself, but when I click on the button during post back, the page shows a blank screen. I want to show a loading message instead of this. I used javascript to show a div which was hidden intitially and shown when the user clicks the button, but when the post back happens, the screen becomes blank. Any idea how to show the loading messsage in this scenario?
Thanks in advance.
Do you really need to avoid ASP.NET ajax or JQuery?
If so: move the heavy processing into an invisible IFRAME. Action your form to the invisible IFRAME, or use javascript to set the location of the IFRAME.
Your 'loading' javascript will display fine. When the form inside the IFRAME completes it just needs to output some javascript to tell the 'parent' to go to location or refresh.
If you use Ajax to post back to the form asynchronously, you can use the UpdateProgress control. Here is a link to an article explaining how to implement the functionality:
How to make a Gmail-like loading indicator with ASP.NET Ajax
Basically, you can't using just postbacks. The browser draws the screen white while waiting for a response from the server. That message you set to show when the user clicks a button was the correct approach (so good work).
But the browser drew the screen white, thinking "Oh boy I'm about to get a response!" and then waited for longer than you think is appropriate.
The only thing you could try would be, in the response, make the very first thing to stream to the browser some sort of loading message that the browser can display while loading the rest (like the gmail loading screen). But personally, I think you could spend your time doing some other development.
You could try other techniques with AJAX though.

Using XMLHttpRequest to display a popup

I am writing an ASP.NET 3.5 web app that displays a list of items. I want to be able to display a non-modal popup with details when the user selects an item. I want to be able to display several detail popups simultaneously. (i.e., the user can click an item to see its details, then click another item to get another popup.) Currently I call RegisterStartupScript during postback to write a "window.open(...)" script to the page when it re-renders. The problem, of course, is that this requires a full page postback and refresh.
It occured to me that this might be a perfect use for XMLHttpRequest or AJAX but I don't know how to do it (or whether it's even possible or smart to do this). Can someone show me the way?
I have the AJAX Extensions installed but I'd prefer not to use the AJAX Control Toolkit.
EDIT:
Some clarification: When the user selects an item a custom event is raised. On the server I handle this event and use some server-side logic to construct a URL which I then use with RegisterStartupScript to construct a "window.open(myUrl...)" script. But posting back the whole page to do this seems inefficient and I'd like to know if I can just make a call to a simple server-side function that constructs the url and sends it back without having to roundtrip the entire page.
Creating a popup has very little to do with AJAX, and a lot more to do with JavaScript. See the jQuery dialog library here. You can then use jQuery's AJAX API to do your server dirty work :)
jQuery Dialog UI
--
Bill Konrad
Devtacular - Web Development Tutorials
You can use DHTML Window widget.
It offers many way to display either modal or non modal window.
Also it supports AJAX.
You can use dhtmlwindow for open a new window, or
dhtmlmodal to open a new modal window.
Of course, you can edit it to match your requirement.
Sample:
var insWindow = dhtmlmodal.open("insbox", "iframe","UserMaster.aspx?" + queryStr, "User Master", "width=425px,height=500,center=1,resize=0,scrolling=1", "recal");
Do you really need to open a new window? Opening an absolutely positioned DIV or a new layer on top of the current page in the same window is all the rage these days.
Edit:
I don't think it would limit the number of popups, there is some neat stuff that can be done these days with libraries like jQuery + jQuery UI, you can simply create as many of these DIVs/layers as you need and make them movable, resizable, etc. Only thing that real popups have and these do not is that they do not appear on the tab panel/taskbar.
Yes, you will be limited to the size of the window in which is the main page opened, however, I don't personally see it as a problem since most people surf in a maximized browser window anyways.
Implementation of the oldschool typical popup window is undoubtedly much easier for you, but it also runs into problems with end user popup blockers. Just had that problem # my work, they needed to make a popup during the certificate authentication process for some reason and as soon as Yahoo released a new version their toolbar, it quit working).

Resources