Solved

ASP.NET C# Hyperlink passing values back to parent form

Posted on 2004-09-30
4
255 Views
Last Modified: 2012-06-22
Hi there...

Been pulling my hair out over this and I am obviously missing something simple and need another pair of eyes... so please help... :-)

I have a simple form that looks like this:

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<script runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
      btnAddressFinder.Attributes.Add("onclick", "window.open('address-finder.aspx?  txtAddressFinder=test','popup','width=250,height=250,left=270,top=180');");

}
</script>
<html>
<title></title>
</head>
<form id="Form1" method="post" runat="server">

<table width="742">
      <tr>
            <td width="20">&nbsp;</td>            
      <td>
        <h1>Postal Address</h1>
        <table width="100%" border="0">
          <tr>
            <td width="30%"><p><strong>Title</strong></p></td>
            <td width="70%"><asp:dropdownlist AutoPostBack="false" ID="ddTitle" runat="server"></asp:dropdownlist></td>
          </tr>
          <tr>
            <td width="30%"><p><strong>First name</strong></p></td>
            <td width="70%"><asp:textbox ID="txtFirstName" runat="server" TextMode="SingleLine" /></td>
          </tr>
          <tr>
            <td width="30%"><p><strong>Surname</strong></p></td>
            <td width="70%"><asp:textbox ID="txtSurname" runat="server" TextMode="SingleLine" /></td>
          </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2"><p><strong>Please enter your postcode in the textbox
                below and click &quot;Address Finder&quot; to let us complete
                your address details for you.</strong></p></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td width="30%">&nbsp;</td>
            <td width="70%">
                <asp:textbox ID="txtAddressFinder" runat="server" TextMode="SingleLine" />
                <asp:button ID="btnAddressFinder"  Text="Address Finder" runat="server"/></td>
          </tr>
        </table>
</form>
</body>
</html>

The address finder popup is working fine... and the address finder popup looks like this:

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<script runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
      
      HyperLink1.NavigateUrl = "javascript:;";
      HyperLink1.Attributes.Add("onclick", "window.opener.document.forms(0).txtAddressFinder.value='2222';self.close()");
      
}
</script>
<html>
<head>
<title>Postal Address Finder</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form runat="server">
      <asp:hyperlink runat="server" ID="HyperLink1" ToolTip="Hyperlink">Hyperlink</asp:hyperlink>
</form>
</body>
</html>

The problem I am having is that when I click on the link nothing happens? If I remove the part of the script to post the value back to the form - and just leave the self.close() - it works fine and the popup closes?

Can anyone see what I am doing wrong here?

Thanks for the help!

g|a|m|b|r|i|n|u|s



0
Comment
Question by:gambrinus
4 Comments
 
LVL 1

Accepted Solution

by:
muellerfan earned 50 total points
ID: 12191463
First, I would change this line: window.opener.document.forms(0).txtAddressFinder.value
to this: window.opener.document.forms[0].txtAddressFinder.value

I've always used [] and not (), but I don't know if that matters at all.

Also, you should put a name field on the textbox along with the ID ( Name="txtAddressFinder")

If that doesn't help, you can see where your error is, but doing alerts.  First alert(window) then alert(window.opener) then alert(window.opener.document) and so on.  You should be able to figure out what is causing your problem.

Good Luck!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Hidden Field Value 10 60
Adjust the position 3 47
Code works but I need to redo it and assign values to Model 7 32
IIS Authorization for Web Service 2 21
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now