Run function after closing popup window in asp.net - javascript

How can I run a function after closing the popup window?
This is my button click to open the popup window:
ImageButton btnEdit = (ImageButton)sender;
GridViewRow row = (GridViewRow)btnEdit.NamingContainer;
string url;
url = "Add-Bank.aspx?a=E&id=" + txtEmployeeCode.Text.Trim() + "&acc=" +
((HiddenField)row.FindControl("hidRecID")).Value;
Response.Write("<script>window.open('" + url + "',400,600);</script>");
And in my popup window, close button code is:
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
When I close the popup window how can I run the specific function or button click event?
What I tried is so far
I created one click even called btnRefresh:
protected void btnRefresh_Click(object sender, EventArgs e)
{
LoadData();
}
I tried to run this event from popup window but it's not hitting the event as:
<script type="text/javascript">
$(document).ready(function () {
var cpframe = top.document.getElementById('contframe');
if (cpframe) {
cpframe.contentWindow.document.getElementById('Main_btnRefresh').click();
}
});
</script>
thanks in advance.

Related

Mobile application how to prevent the confirm box is not closed when i clicked outside this dialog

Can you please explain how we will use the code below because we do not have a dialog:
var message = text;
var title = "INFO";
var buttonLabels = "OK";
navigator.notification.confirm(message, null, title, buttonLabels);
Can somebody explains in mobile application how to get the above dialog to close when i clicked outside this dialog?
It's only closed when i clicked on OK button.
new AlertDialog.Builder(this)
.setTitle(Your Title)
.setMessage(Your Message)
.setCancelable(true)
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int which) {
//Action to be performed on click `
}
})
.setNegativeButton("No", null)//Keep If you want to
.show();
Try This..

Telerik RadMenu Click To Open and Close when clicked to next page

Hi im having problem with my radmenu. I want it to click to open and not open as you hover. I have set the clicktoopen = "true" already. Now the problem is when i click, it navigate to the respective requested page but the menu doesn't close.
<script type="text/javascript">
function OnClientItemClicking(sender, args) {
if (args.get_item().get_isOpen() == true) {
args.set_cancel(true);
args.get_item().close();
}
else {
}
}
</script>
<script type="text/javascript">
function OnClientMouseOverHandler(sender, eventArgs) {
if (eventArgs.get_item().get_parent() == sender) {
sender.set_clicked(false);
}
}
function onClientItemClicked(sender, args) {
}
</script>

Redirect to a page after a pop up opens

I am trying to redirect a web page after a condition is returned as true but I can't seem to get it work. In theory this should, shouldn't it. What am I missing, is it even possible!
protected void btnVerify_Click(object sender, EventArgs e)
{
if (value == txtVerification.Text || txtVerification.Text == "****")
{
//defines a bool to tell if the popup window has been shown, this will only ever return true
bool PopupShown = doRedirect();
if(PopupShown)
{
Response.Redirect("somewebpage.aspx");
}
}
else
{
lblVerificationFailed.Visible = true;
}
}
//Opens the popup window to fire off the download and returns true
bool doRedirect()
{
string url = "GetDocs.aspx";
string s = "window.open('" + url + "', 'GetDocs', 'height=150,width=300,left=100,top=30,resizable=No,scrollbars=No,toolbar=no,menubar=no,location=no,directories=no, status=No');";
ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
return true;
}
You are trying to do in the server things that can be much more easily done on the client side.
You're using a server event to catch the click of a button on your view, launch a client popup and later redirect your page execution.
Try with something like this on javascript:
var btnVerify = document.getElementById("btnVerify");
btnVerify.addEventListener("click", function() {
window.open('GetDocs.aspx', 'GetDocs', 'height=150,width=300,left=100,top=30,resizable=No,scrollbars=No,toolbar=no,menubar=no,location=no,directories=no, status=No');
window.location.href = "somewebpage.aspx";
});
Sussed it, if I use window.location.replace instead of window.location it works exactly like I want it to. Many thanks all :)

Confirmation box before closing tab, not when page is reloaded

My client requirement is to give an alert message when browser tab of my web application is closed. It can be done using JavaScript onunload or onbeforeunload event.
But there are many drop-down boxes in my application and selecting some of drop-down boxes, page needs to be reloaded. During this reloading each time onunload or onbeforeunload is fired and alert message is displayed. I want to stop firing this onunload or onbeforeunload event on reloading page but display alert message when browser tab is closed. If there were any changes in URL, it would be helpful. But my URL is not changed.
I know there is no direct JavaScript event support for this situation. Can anyone suggest alternative solution?
Update:
<script language="JavaScript1.2" type="text/javascript">
var g_isPostBack = false;
function windowOnBeforeUnload()
{
if ( g_isPostBack == true )
return; // Let the page unload
if ( window.event )
window.event.returnValue = 'Are you sure?'; // IE
else
return 'Are you sure?'; // FX
}
window.onbeforeunload = windowOnBeforeUnload;
</script>
Code behind:
protected void Page_Load(object sender, EventArgs e)
{
this.ClientScript.RegisterOnSubmitStatement(this.GetType(), "OnSubmitScript", "g_isPostBack = true;");
}
try the below code and update us if this is your requirement.
<script type="text/javascript">
var new_var = true;
window.onbeforeunload = function () {
if (new_var) {
return "you have unsaved changes, if you leave they will be lost"
}
}
function unhook() {
new_var = false;
}
</script>
faced the same problem try this script
<script language="JavaScript" type="text/javascript">
window.onbeforeunload = confirmExit;
function confirmExit() {
return "You are about to exit the system before freezing your declaration! If you leave now and never return to freeze your declaration; then they will not go into effect and you may lose tax deduction, Are you sure you want to leave now?";
}
$(function() {
$("a").click(function() {
window.onbeforeunload = null;
});
$("input").click(function() {
window.onbeforeunload = null;
});
});
</script>

javascript open parent window

The following is in the NewForm.aspx which gets executed from a parent page (surveys/lists/testsurvey/allitems.aspx). The javascript works and open google. However, it opens the google in the pop up window (newform.aspx) but i need to close the popup window and show google.com on the parent window (or whatever the parent window link is)
<script type="text/javascript">
function redirect()
{
var inputcCtrls = document.getElementsByTagName("input");
for(m=0; m<inputcCtrls.length; m++)
{
if(inputcCtrls[m].type == 'button' && inputcCtrls[m].value == 'Finish')
{
var funcOnClick = inputcCtrls[m].onclick;
inputcCtrls[m].onclick = function () { window.location = "http://www.google.com/" }; }
}
}
redirect();
</script>
Use the opener property to find the window that opened the current window:
window.opener.location = "http://www.google.com/";
window.close();

Categories

Resources