Navigate to another page from radwindow - asp.net

Scenario:-
I've a local asp.net website directory :- "http://localhost/DemoWebsite/". A "Secure" folder is inside it. Two webpages are inside that folder :- Page1.aspx and Page2.aspx. And one more webpage:- Page3.aspx is outside the folder.
Requirement:-
Now 'Page2.aspx' is opening in a RadWindow from the parent page 'Page1.aspx'. A button 'Cancel' is there in 'Page2.aspx' and on-click of that button I want to come out of RadWindow and directly move to 'Page3.aspx'.
Attempted Solution:-
Button's 'OnClientClick' event is set to a JS function 'LogOff()'.
Definition is:-
function LogOff()
{
top.location.href = "http://localhost/DemoWebsite/Page3.aspx";
}
The Problem is that since I can't give the above mentioned enitre link when I want this website to push in some other server. So if I give the link as:-
top.location.href = "~/Page3.aspx"; OR Just, top.location.href = "Page3.aspx";
And when I run the website and click the Cancel Button. It throws error "Resource can't be found." It is because after button click it tries the link "/DemoWebsite/Secure/Page3.aspx".
Question:- what to assign for top.location.hrefso that it tries the link "/DemoWebsite/Page3.aspx". As Page3.aspx is NOT in Secure folder.

You could do something like.... GetRadWindow().BrowserWindow.location.href = '../page3.aspx';
GetRadWindow() is a function that gets a reference to your radwindow....
function GetRadWindow()
{
var oWindow = null; if (window.radWindow)
oWindow = window.radWindow; else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow; return oWindow;
}
The BrowserWindow part will get a reference to your window that the radwindow opened from. The rest just redirects the opening window to the location that you want.
EDIT: after looking at your question again i think you just need to know how to get to the relative path through javascript? if that is the case it is like this... document.location.href = '../'; //Up one level. The ../ will jump you back one level. If you just use /path then it will assume you are going from the same folder level that your current page is on.

Related

How can I create a name prompt before page loads and add its content to iframe src on the same page?

I have this page on my website:
https://www.lior.vip/chat
When this page loads, there is an iframe in the center of the page that runs video chat system that works like zoom.
Before the page loads, I want a popup to appear that asks the user to enter his name with two buttons: "ok / continue without name"
When user enters his name and hits "ok",
I want this name to be added to the iframe src.
For example,
if the iframe src is: "https://www.videoconf.com/room1"
I want the source to be: "https://www.videoconf.com/room1/displayName=what user entered at name prompt.
And if user hitted "continue without name",
I want the iframe src stay the regular (https://www.videoconf.com/room1).
How can I do it?
The most simple way is use prompt comand. For example, you can write this code right after body tag in your page.
<script>
let displayName = "";
const namePrompt = prompt("If you want to enter anonymous you can click 'Cancel' button, else insert your name here:");
if (namePrompt !== null) {
displayName = "/displayName="+namePrompt;
}
document.getElementById("Iframe Id").src = "your url source"+displayName;
</script>
If you prefer you can create dinamically a popup window with javascript. Or put the code inside a function and get the name as return value.

Reloading a parents iframe from a child

I have two iframes on my page, frameOne and frameTwo.
I'm trying to refresh/reload frameOne from a script running in frameTwo.
function reload(){
srcLink = parent.document.getElementById('frameOne').src;
parent.document.getElementById('frameOne').src=srcLink;
}
This works but it refreshes to the initial value of the iframe.
IE:
If the parent page loaded with that iframe's src set to 'google.com' but then changed to (due to a user action) 'yahoo.com' my code will refresh that page to 'google.com', the link it was set to when the page was loaded. I would like to take into account the change of link and refresh that one.
Try this from frames[1] (the 2nd iframe page):
function changeFrameSrc(becauseURL, changeURL){
var bc = new RegExp(becauseURL, 'i');
if(bc.test(location)){
parent.frames[0].src = changeURL;
}
}

Server side equivalent of "top.location.href"

I'm in 'Home' page. From there 'Child' page is called in a radwindow. Now on a click event of 'Child' page, I want to close the radwindow and reload page 'Home' page.
Inorder to achieve this, on the click event of a button defined in 'Child' page. I am calling a JavaScript function:-
function ReloadHome
{
var abc = 'Home.aspx';
top.location.href = abc;
}
Question:- How to close radwindow and then navigate or reload 'Home' page, using a server side method. Not the javascript mentioned above.
You can try with
Close :
Response.Write("<script language='javascript'> { window.close();}</script>")
Redirect :
Response.Redirect("...Your url");

ASP.NET postbacks lose the hash in the URL

On an ASP.NET page with a tabstrip, I'm using the hash code in the URL to keep track of what tab I'm on (using the BBQ jQuery plugin). For example:
http://mysite.com/foo/home#tab=budget
Unfortunately, I've just realized that there are a couple of places on the page where I'm using an old-fashioned ASP.NET postback to do stuff, and when the postback is complete, the hash is gone:
http://mysite.com/foo/home
... so I'm whisked away to a different tab. No good.
This is a webforms site (not MVC) using .NET 4.0. As you can see, though, I am using URL routing.
Is there a way to tell ASP.NET to keep the hash in the URL following a postback?
The problem is that the postback goes to the url of the current page, which is set in the action of the form on the page. By default this url is without #hash in asp.net, and its automatically set by asp.net, you have no control over it.
You could add the #hash to the forms action attribute with javascript:
document.getElementById("aspnetForm").action += location.hash
or, if updating an action with a hash already in it:
var form = document.getElementById("aspnetForm");
form.action = form.action.split('#')[0] + location.hash
just make sure you execute this code on window.load and you target the right ID
I tried to put the code from Willem's answer into a JS function that got called everytime a new tab was activated. This didn't work because it kept appending an additional #hash part to the URL every time I switched tabs.
My URL ended up looking like http://myurl.example.com/home#tab1#tab2#tab3#tab2 (etc.)
I modified the code slightly to remove any existing #hash component from the URL in the <form> element's action attribute, before appending on the new one. It also uses jQuery to find the element.
$('.nav-tabs a').on('shown', function (e) {
// ensure the browser URL properly reflects the active Tab
window.location.hash = e.target.hash;
// ensure ASP.NET postback comes back to correct tab
var aspnetForm = $('#aspnetForm')[0];
if (aspnetForm.action.indexOf('#') >= 0) {
aspnetForm.action = aspnetForm.action.substr(0, aspnetForm.action.indexOf('#'));
}
aspnetForm.action += e.target.hash;
});
Hope this helps someone!
I have another solution, implemented and tested with chrome, IE and safari.
I am using the "localStorage" object and it suppose to work all the browsers which support localStorage.
On the click event of tab, I am storing the currentTab value to local storage.
$(document).ready(function() {
jQuery('.ctabs .ctab-links a').on('click', function(e) {
var currentAttrValue = jQuery(this).attr('href');
localStorage["currentTab"] = currentAttrValue;
// Show/Hide Tabs
jQuery('.ctabs ' + currentAttrValue).show().siblings().hide();
// Change/remove current tab to active
jQuery(this).parent('li').addClass('active').siblings().removeClass('active');
e.preventDefault();
});
if (localStorage["currentTab"]) {
// Show/Hide Tabs
jQuery('.ctabs ' + localStorage["currentTab"]).show().siblings().hide();
// Change/remove current tab to active
jQuery('.ctabs .ctab-links a[href$="' + localStorage["currentTab"] + '"]').parent('li').addClass('active').siblings().removeClass('active');
}
});

Redirect from pop up window

how can i redirect to other page from pop up window with response.redirect.
I'm assuming that you're wanting to do this when the user presses a button or something on the popup. You can use ClientScript.RegisterStartupScript function to get ASP.Net to put some JavaScript in the right place so that it's executed as soon as the postback has completed. Something like this...
public void RedirectParent(string url)
{
string js = "";
js += "window.opener.location.href='" + url + "';";
js += "window.close();";
ClientScript.RegisterStartupScript(this.GetType, "redirect", js, true);
}
You can remove the window.close() line if you want to keep the popup open, but I'm guessing that you want to close it automatically.
The "redirect" bit on the last line is just the name that you want to assign to the script - this can be anything you wish.
Once popup is opened to a given URL you cannot use server side script to redirect the parent. You need to use javascript inside the popup:
if (opener && !opener.closed) {
opener.location.href = "http://www.example.com/somenewurl";
}

Resources