T
Thomas
I'm stuck on trying to get the following to work:
I am using VB.NET to program ASP.NET...my task is to create two pages,
Main and Child. In Main, I have linked a javascript function to a
button in order to popup a second window (Child) where a user can
enter information, hit the button, and the text is passed back to the
calling window (Main). I've successfully done this in classic HTML
before, but for some reason it doesn't seem like my text object on the
Main page is being referenced correctly. I'm not sure if there is a
step between .NET and javascript I am missing. In classic ASP, you
referenced HTML controls by name, but since that is no longer
available, I reference by clientID...is this a problem?
The code is as follows:
-----------
MAIN.ASPX
-----------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="main.aspx.vb" Inherits="WebApplication1.main"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>main</title>
<script id="clientEventHandlersJS" language="javascript">
<!--
var dialogArguments;
function getValue (field){
dialogArguments = field;
open('child.aspx', 'popup', 'width=400,height=300,scrollbars=1')
}
//-->
</script>
</HEAD>
<body>
<form id="formMain" method="post" runat="server">
<P> </P>
<P>
<asp:Button id="buttonMain" runat="server" Text="Get
Input"></asp:Button></P>
<P>
<asp:TextBox id="textMain" runat="server"></asp:TextBox></P>
</form>
</body>
</HTML>
---------------
MAIN.ASPX.VB
---------------
Public Class main
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents button1 As System.Web.UI.WebControls.Button
Protected WithEvents firstName As
System.Web.UI.WebControls.TextBox
Protected WithEvents buttonMain As
System.Web.UI.WebControls.Button
Protected WithEvents textMain As System.Web.UI.WebControls.TextBox
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
buttonMain.Attributes.Add("onClick",
"getValue(document.getElementById('" & textMain.ClientID & "'))")
End Sub
End Class
------------
CHILD.ASPX
------------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="child.aspx.vb" Inherits="WebApplication1.child"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>child</title>
<script id="clientEventHandlersJS" language="javascript">
<!--
function buttonChild_onclick(){
var doc = document.forms[0];
if (doc.textChild.value == ""){
alert("Email message is empty.");
return false;
}
else
{
//alert(doc.textChild.value);
window.opener.dialogArguments.value = this.textChild.value;
window.close()
}}
//-->
</script>
</HEAD>
<body>
<form id="formChild" method="post" runat="server">
<asp:Button id="buttonChild" style="Z-INDEX: 101; LEFT: 216px;
POSITION: absolute; TOP: 136px"
runat="server" Text="Submit"></asp:Button>
<asp:TextBox id="textChild" style="Z-INDEX: 102; LEFT: 48px;
POSITION: absolute; TOP: 136px"
runat="server"></asp:TextBox>
</form>
</body>
</HTML>
--------------
CHILD.ASPX.VB
--------------
Public Class child
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents button1 As System.Web.UI.WebControls.Button
Protected WithEvents buttonChild As
System.Web.UI.WebControls.Button
Protected WithEvents textChild As
System.Web.UI.WebControls.TextBox
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
buttonChild.Attributes.Add("onClick", "return
buttonChild_onclick()")
End Sub
End Class
I am using VB.NET to program ASP.NET...my task is to create two pages,
Main and Child. In Main, I have linked a javascript function to a
button in order to popup a second window (Child) where a user can
enter information, hit the button, and the text is passed back to the
calling window (Main). I've successfully done this in classic HTML
before, but for some reason it doesn't seem like my text object on the
Main page is being referenced correctly. I'm not sure if there is a
step between .NET and javascript I am missing. In classic ASP, you
referenced HTML controls by name, but since that is no longer
available, I reference by clientID...is this a problem?
The code is as follows:
-----------
MAIN.ASPX
-----------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="main.aspx.vb" Inherits="WebApplication1.main"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>main</title>
<script id="clientEventHandlersJS" language="javascript">
<!--
var dialogArguments;
function getValue (field){
dialogArguments = field;
open('child.aspx', 'popup', 'width=400,height=300,scrollbars=1')
}
//-->
</script>
</HEAD>
<body>
<form id="formMain" method="post" runat="server">
<P> </P>
<P>
<asp:Button id="buttonMain" runat="server" Text="Get
Input"></asp:Button></P>
<P>
<asp:TextBox id="textMain" runat="server"></asp:TextBox></P>
</form>
</body>
</HTML>
---------------
MAIN.ASPX.VB
---------------
Public Class main
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents button1 As System.Web.UI.WebControls.Button
Protected WithEvents firstName As
System.Web.UI.WebControls.TextBox
Protected WithEvents buttonMain As
System.Web.UI.WebControls.Button
Protected WithEvents textMain As System.Web.UI.WebControls.TextBox
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
buttonMain.Attributes.Add("onClick",
"getValue(document.getElementById('" & textMain.ClientID & "'))")
End Sub
End Class
------------
CHILD.ASPX
------------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="child.aspx.vb" Inherits="WebApplication1.child"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>child</title>
<script id="clientEventHandlersJS" language="javascript">
<!--
function buttonChild_onclick(){
var doc = document.forms[0];
if (doc.textChild.value == ""){
alert("Email message is empty.");
return false;
}
else
{
//alert(doc.textChild.value);
window.opener.dialogArguments.value = this.textChild.value;
window.close()
}}
//-->
</script>
</HEAD>
<body>
<form id="formChild" method="post" runat="server">
<asp:Button id="buttonChild" style="Z-INDEX: 101; LEFT: 216px;
POSITION: absolute; TOP: 136px"
runat="server" Text="Submit"></asp:Button>
<asp:TextBox id="textChild" style="Z-INDEX: 102; LEFT: 48px;
POSITION: absolute; TOP: 136px"
runat="server"></asp:TextBox>
</form>
</body>
</HTML>
--------------
CHILD.ASPX.VB
--------------
Public Class child
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents button1 As System.Web.UI.WebControls.Button
Protected WithEvents buttonChild As
System.Web.UI.WebControls.Button
Protected WithEvents textChild As
System.Web.UI.WebControls.TextBox
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
buttonChild.Attributes.Add("onClick", "return
buttonChild_onclick()")
End Sub
End Class