Link to home
Avatar of maheshneel
maheshneel

asked on

popup window asp.net

Hi,
I am using following code for popup control in asp.net 2.0 with c# as code behind.

    protected void Page_Load(object sender, EventArgs e)
    {
         Button1.Attributes.Add("onclick", "window.confirm('You are about to delete a record, would you like to continue ?')");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
            Response.Redirect("~/TimeTracker/TimeEntry.aspx");
    }
When i click the asp: Button1 the popup window shows but the problem with this is after popup window is displayed clicking ok and cancel both are  taking me to timeentry.aspx page. only ok should take me to the nextpage.aspx.

I need some help on passing values from popup window to the main window.
ASKER CERTIFIED SOLUTION
Avatar of dakyd
dakyd

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of maheshneel
maheshneel

ASKER

Thanks a lot. That one worked.....

And i have one asp: textbox in the pop up window whose value must be passed to the main window. How do i do this?
I have to pass values from text boxes of popup window to the main window.
Can any one help me out in this.
You need to use window.opener .  Since you open the window yourself via window.open, you have access to the opener.  Here's a very simple example:

test.html (has a link that opens another window)
<html>
<body>
<a href="#" onclick="window.open('test2.html'); return false;">Open new window</a>

<form>
  <input type="text" name="key" value="">
</form>
</body>
</html>

test2.html (sets a value in test.html on load):
<html>
<head>
<script type="text/javascript">
window.onload = function()
{
  window.opener.document.forms[0].key.value = "value";
};
</script>
</head>

<body>
<table id="tbl1">
  <tr>
    <td>Table 1</td>
  </tr>
</table>
</body>
</html>

Hope that helps.