Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > ASP.NET - VB.NET - JavaScript Question

Reply
Thread Tools

ASP.NET - VB.NET - JavaScript Question

 
 
Thomas
Guest
Posts: n/a
 
      12-03-2004
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>&nbsp;</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
 
Reply With Quote
 
 
 
 
Jorge Ponte
Guest
Posts: n/a
 
      12-19-2004
Hi Thomas

Try This:

--------------
MAIN.ASPX
--------------

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="main.aspx.vb"
Inherits="PopUpSample.main"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>main</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script id="clientEventHandlersJS" language="javascript">


function getValue (src){

open('child.aspx?src=' + src, '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('textMain')")

End Sub

End Class


---------------
CHILD.ASPX
---------------

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="child.aspx.vb"
Inherits="PopUpSample.child"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>child</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language="javascript" id="clientEventHandlersJS">
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
------------

Imports System.Text

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

Private Sub buttonChild_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles buttonChild.Click

Dim sbScript As New StringBuilder
sbScript.Append("<script language='javascript'>")
sbScript.Append(Environment.NewLine)
sbScript.Append("window.opener.document.forms[0].")
sbScript.Append(Request.QueryString("src"))
sbScript.Append(".value = '")
sbScript.Append(textChild.Text)
sbScript.Append("';")
sbScript.Append(Environment.NewLine)
sbScript.Append("window.close();")
sbScript.Append(Environment.NewLine)
sbScript.Append("</script>")
RegisterStartupScript("CloseWindow", sbScript.ToString)

End Sub
End Class

-------------------------

Hope it works.

Jorge Ponte











"Thomas" wrote:

> 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
>

 
Reply With Quote
 
 
 
 
Jorge Ponte
Guest
Posts: n/a
 
      12-19-2004
Sorry, I've made a mistake

In the Child.aspx You dont need the script tag, beacuse you'll add it in run
time.
So child.aspx will be:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="child.aspx.vb"
Inherits="PopUpSample.child"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>child</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">

</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>


Jorge Ponte

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about question mark in JavaScript Jimolo Javascript 2 01-20-2008 05:02 PM
Generated JavaScript vs. Manually Created JavaScript: Which one comes first? Nathan Sokalski ASP .Net 4 11-08-2007 07:24 AM
JavaScript or not JavaScript Mark Rae ASP .Net 36 09-09-2006 01:12 PM
href="javascript:func()" vs href="#" onclick="javascript:func()" CRON HTML 24 06-20-2006 08:05 PM
Javascript -> Applet: variable reset after method call from javascript?! mcdeveloper Java 1 06-13-2006 08:34 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57