Call PageLoad of parent page after closing modal popup - c#

I have a parent page to display the project details, and user enter part details by uploading a template in a modal pop-up.
To open the modal popup I'm calling this function
function importfile()
{
var url="SCN_UploadPart.aspx";
var selSCE=window.showModalDialog(url,'win','help:no;status:no;scroll:no;resize:no;dialogHeight:300px;dialogWidth:490px');
return false;
}
Earlier I was using OnClinetClick method of Uplaod Button to call this method, then the project page or parent page was automatically reloading. But now I'm calling it like this.
ClientScript.RegisterStartupScript(this.GetType(), "project", "<script language='javascript'>importfile();</script>");
onclick of same Upload Button.
I font why the page does not reload now. I want the page to be reloaded as I am showing the content in the parent page after uploading the parts.
Please suggest me the way to reload the Parent page on click of close in modalpopup.

U can refer below link its show the demo
http://codedisplay.com/automaticaly-refresh-parent-window-whenever-popup-window-is-closed/
http://www.mindfiresolutions.com/Refresh-parent-page-on-closing-modal-child-windowpopup-29.php
Hope it helps u

Related

maintain login and logout sessions in asp.net web forms

I am trying to implement login and logout in asp.net(web forms). In my web form I have two pages namely Default and Main. From Default page when I login with username and password it redirects to the Main page. When I press back button it directly redirects to the default page. For this I copied javascript code to my default page
<script type = "text/javascript" >
function preventBack() { window.history.forward(); }
setTimeout("preventBack()", 0);
window.onunload = function () { null };
source from stackoverflow question
After login when I click on back button in my browser(chrome) first it shows the Default page and then it shows the Main page. i.e page blinks when I click the back button.
It shows main page successfully with the issue.
What should I implement to stop showing the Default page when I click on back button
Update:
<script type = "text/javascript" >
history.pushState(null, null, 'Default.aspx');
window.addEventListener('popstate', function (event) {
history.pushState(null, null, 'Default.aspx');
});
</script>
I placed this code in default page
There is one important thing that you ought to know here.
One cannot disable the browser back button functionality only thing that can be done is prevent it.
You can't, in anyway diasble that button. What you can however do, is to put some logic and prevent that button from doing what it is meant to do.
Now for the script that you have shown, it should serve fine and the other thing to try here is to put a mediator page between your default and main page. So when you login, the control will flow to mediator page and it will then redirect to main page. Now when the user presses back button on the main page, the control will flow to mediator page which will again redirect the user to his main page.
The effect will be the same as your script, but putting a page can help you write Session handling code and some server side checks if you want.
But one thing is sure, the browser back button will be as it is.
Hope this helps.
As Matt said you can't disagree the back behaviour. However you can check if the user is logged in and redirect them to the main page easily.
All you need to do is, on the default page check if the user is logged in, if they are then redirect them to the main page, this way even if the user clicks back, they will be taken back to the main page. And also the can go to the Default page after logging out.
Another way could be using location.replace("...."), which replace the existing document and user can't "go back" using back button as the page doesn't exist in the url history.
Src: https://developer.mozilla.org/en-US/docs/Web/API/Location/replace

close a modal popup from an iframe

I am using modal.js to pop up dialog box in a page. When the user clicks on a link an iframe will show on a modal dialog box. There is a button inside that iframe. When the button clicks, the modal should be closed and page should redirect to another url. Is it posssible?
You can use jQuery binding to trigger a custom event.
On the click, before you show the iframe, do the following in javascript:
// Bind a trigger
$('body').unbind('myUniqueEventName', SomeJavascriptFunction);
$('body').bind('myUniqueEventName', SomeJavascriptFunction);
Elsewhere in javascript define the function SomeJavascriptFunction:
function SomeJavascriptFunction(event, extraData) {
// This is run when the button on the popup is clicked
// You can pass along data using the extraData parameter
// You can also redirect to another page
var someData = extraData.someData; // Will contain 'someValue'
}
Now all we have to do is trigger the custom event from the iframe. We do this by adding the following code in the iframe when the button is clicked.
parent.$('body').trigger(
'myUniqueEventName', {
someData: 'someValue'
});
});

Javascript Redirection after the alert message

I have one asp.net page , it consists of some controls along with a close button. If the user clicks on the close button, it will open ModaldialogBox with one text box for entering closing reason. Once the user enters the reason and clicking on the save button, the modal popup shows the alert message and close the modal popup. The existing code for this is shown below.
this.Page.ClientScript.RegisterStartupScript(GetType(), "close", "alert('" + Message + "');var xWin=window.dialogArguments;xWin.location.replace(xWin.location);window.close();", true);
My requirement is that, once the user click on the submit button, I have to navigate to the dashboard page after closing the modal popup window.
I had tried window.location.href after the window.close(), It will open another window and displyed the page. But it should navigate from the existing asp parent page. Please help me for resolving this issue.
Thanks in advance
redirect the parent window with following code
window.opener.parent.location.href = 'dashboardurl';

Close iframe fancybox when child page submitted and reload parent page

I have iframe fancybox on my page. On the child page, I add something to DB when Add Button clicked. After this process I want to close the fancybox and reload the parent page. How can I do it?
this should be called on page reload..
window.parent.closeDialogFormSubmit();
//Or
window.top.parent.closeDialogFormSubmit();
this closeDialogFormSubmit function should be on fancy box open on that page.
closeDialogFormSubmit write code for fancy box close code.
the function should be written outside $(document).ready(function(){}); or $(function(){}); else it will not find the function and gives error undefined.
1). In the child page
Use the API method parent.$.fancybox.close()
You could create a button like :
<img src="myCloseButton.png" alt="close fancybox" />
Bear in mind that interaction between those pages is subject to the same origin policy so if the child page is in another domain parent.$.fancybox.close() may not work.
EDIT : if the child page should be closed after a form is submitted, then set the closing method using the onsubmit attribute in the form tag like :
<form id="login_form" action="process.php" onsubmit="javascript:parent.jQuery.fancybox.close();">
See this post for further reference and demo.
2). In the parent page
Add to your custom script the afterClose callback like :
$(".fancybox").fancybox({
afterClose : function() {
location.reload();
return;
}
});
... to reload the page after closing fancybox. See JSFIDDLE

how to reload the parent page from popup window without deleting control values

i have created two aspx pages, parent and popup page.I want to refresh parent page after some operation in popup is completed.I am using the Page.RegisterStartupscript Option for the reloading the parent page but if i call some server event from parent page that also repeat twice..i dont need that...i tried out each soln what i can do ...but nothing works so please help me out...
i am waiting for reply........
here is some code by which i am getting resend or cancel popup window from the parent page....
//In Popup.aspx.cs file
Session["txt"]=txtval.Text;
Page.RegisterStartUpScript("ReloadParent","window.opener.location.reload(false);");
//in Parent.aspx.cs file
Response.Write(Session["txt"]);
--->some event is calling after this statement in page load...
pls hel me....
You can try to do
window.opener.__doPostBack();

Categories