473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Open a JavaScript Window from a Web User Control and return a valu

hi

I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In
that WUC I want have a textbox and a button. I want to click on the button
and open a popup (I use javascript for that), the popup window will have also
a text box and a button. when the User click on the button the value on the
textbox will be send back to the textbox on My_WUC. I hope I was clear off
what I want to do.

I've been searching for some ideas but I found nothing that would suit me...

I think my problem is that I'm not able to find the textbox in My_WUC
because the ID is dynamic...

This is my code:

------------------
My_WUC.aspx
------------------

<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="WUC_EnviarMensagem.ascx.vb" Inherits="SiteICS.WUC_EnviarMensagem"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<LINK href="ASPNETPortal.css" type="text/css" rel="stylesheet">

<script language="javascript" id="openContactsPageJS">
function getValue (src){
open('child.aspx?src=' + src, 'popup', 'width=400,height=300,scrollbars=1')
}
</script>

<TABLE id="Table1" height="80%" cellSpacing="0" cellPadding="0" width="100%"
border="0">
<TR>
<TD width="10%"><label class="Normal" id="lbl_To">To :</label></TD>
<TD width="85%" colSpan="3"><asp:textbox id="txtb_Destinations"
tabIndex="2" runat="server" Width="100%"
CssClass="NormalTextBox"></asp:textbox></TD>
<TD vAlign="middle" align="center" width="5%"><asp:button
id="bt_adicionarDestinos" runat="server" CssClass="button_blue_2"
Text="Add"></asp:button></TD>
</TR>
</TABLE>

---------------------
My_WUC.aspx.vb
---------------------

Public Class WUC_EnviarMensagem
Inherits System.Web.UI.UserControl

Protected WithEvents bt_adicionarDestinos As
System.Web.UI.WebControls.Button
Protected WithEvents txtb_Destinations As
System.Web.UI.WebControls.TextBox

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
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

bt_adicionarDestinos.Attributes.Add("onClick",
"getValue('txtb_Destinations ')")
End Sub

End Class
---------------------------------------------------------------------------------
As You can see I have a javascript function that opens "child.aspx" with a
query ?src= src, and I use
"bt_adicionarDestinos.Attributes.Add("onClick" , "getValue('txtb_Destinations
')")" to set the "onClick" event of the button to it passing the textbox.

this it the child.aspx code

------------
child.aspx
------------

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="child.aspx.vb"
Inherits="SiteICS.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>

---------------------
child.aspx.vb
---------------------
Public Class child
Inherits System.Web.UI.Page

Protected WithEvents control As New
System.Web.UI.HtmlControls.HtmlInputHidden

#Region " Web Form Designer Generated Code "

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

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

control.Value = Request.QueryString("src").ToString()

End Sub

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

Dim strScript As String = "<script>window.opener.form[0]." &
control.Value '.Value= '"
strScript += Me.textChild.Text
strScript += "';self.close()"
strScript += "</" + "script>"

RegisterClientScriptBlock("CloseWindow", strScript)
End Sub
End Class
-------------------------------------------------------------------------------

Now this is where, I think its the problem...I'm not able to pass the value
to My_WUC textbox...probably is because I can get the ID of that textbox.

Can some onde help?I really need this to solve this problem...and I'm sure
that this is just a stupid mistake...I cant think that it is impossible to
have this kind off "Input Box" with javascript.

Thank you very much in advance.

Jorge Ponte

Nov 19 '05 #1
1 5393
First off, since you are using so much javascript, I'm not sure why your
popup needs to postback, simply use javascript controls. I'd also move the
population javascript code to the user control, which will help the dynamic
id problem you are having.

POPUP (no codebehind)
<input type="text" id="child" /> <input type="button" value="Submit"
onClick="SetValue()

<script language="javascript">
function SetValue(){
var txt = document.getElementById('child');
window.opener.SetValue(txt.value);
self.close();
}
</script>
User Control:
<script language="javascript">
function SetValue(value){
var txt = document.getElementById('<%=txtb_Destinations.Clie ntId%>');
txt.value = value;

}
</script>
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jorge Ponte" <Jo********@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
hi

I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In that WUC I want have a textbox and a button. I want to click on the button
and open a popup (I use javascript for that), the popup window will have also a text box and a button. when the User click on the button the value on the textbox will be send back to the textbox on My_WUC. I hope I was clear off
what I want to do.

I've been searching for some ideas but I found nothing that would suit me...
I think my problem is that I'm not able to find the textbox in My_WUC
because the ID is dynamic...

This is my code:

------------------
My_WUC.aspx
------------------

<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="WUC_EnviarMensagem.ascx.vb" Inherits="SiteICS.WUC_EnviarMensagem" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<LINK href="ASPNETPortal.css" type="text/css" rel="stylesheet">

<script language="javascript" id="openContactsPageJS">
function getValue (src){
open('child.aspx?src=' + src, 'popup', 'width=400,height=300,scrollbars=1') }
</script>

<TABLE id="Table1" height="80%" cellSpacing="0" cellPadding="0" width="100%" border="0">
<TR>
<TD width="10%"><label class="Normal" id="lbl_To">To :</label></TD>
<TD width="85%" colSpan="3"><asp:textbox id="txtb_Destinations"
tabIndex="2" runat="server" Width="100%"
CssClass="NormalTextBox"></asp:textbox></TD>
<TD vAlign="middle" align="center" width="5%"><asp:button
id="bt_adicionarDestinos" runat="server" CssClass="button_blue_2"
Text="Add"></asp:button></TD>
</TR>
</TABLE>

---------------------
My_WUC.aspx.vb
---------------------

Public Class WUC_EnviarMensagem
Inherits System.Web.UI.UserControl

Protected WithEvents bt_adicionarDestinos As
System.Web.UI.WebControls.Button
Protected WithEvents txtb_Destinations As
System.Web.UI.WebControls.TextBox

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
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

bt_adicionarDestinos.Attributes.Add("onClick",
"getValue('txtb_Destinations ')")
End Sub

End Class
-------------------------------------------------------------------------- ------- As You can see I have a javascript function that opens "child.aspx" with a
query ?src= src, and I use
"bt_adicionarDestinos.Attributes.Add("onClick" , "getValue('txtb_Destinations ')")" to set the "onClick" event of the button to it passing the textbox.

this it the child.aspx code

------------
child.aspx
------------

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="child.aspx.vb"
Inherits="SiteICS.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>

---------------------
child.aspx.vb
---------------------
Public Class child
Inherits System.Web.UI.Page

Protected WithEvents control As New
System.Web.UI.HtmlControls.HtmlInputHidden

#Region " Web Form Designer Generated Code "

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

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

control.Value = Request.QueryString("src").ToString()

End Sub

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

Dim strScript As String = "<script>window.opener.form[0]." &
control.Value '.Value= '"
strScript += Me.textChild.Text
strScript += "';self.close()"
strScript += "</" + "script>"

RegisterClientScriptBlock("CloseWindow", strScript)
End Sub
End Class
-------------------------------------------------------------------------- -----
Now this is where, I think its the problem...I'm not able to pass the value to My_WUC textbox...probably is because I can get the ID of that textbox.

Can some onde help?I really need this to solve this problem...and I'm sure
that this is just a stupid mistake...I cant think that it is impossible to
have this kind off "Input Box" with javascript.

Thank you very much in advance.

Jorge Ponte

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Carol Lyn | last post by:
Could use your assistance with this. I have a window that opens via onclick and it is a small window with info about a site. If the user is interested in visiting that site, there is a link to...
10
by: Marshall Dudley | last post by:
When I do the following line in Netscape, the popup loads as it should, but the parent window usually, but not always, reloads as well. <a href="#"...
8
by: Dominic Tocci | last post by:
I'm searching for a way to use window.open on my web page to open a window in firefox that allows the sidebars to work (bookmarks, history, etc). When I use the following: var...
29
by: wayne | last post by:
Hey there... I'm having some problems passing url parameters with an open.window command. I'm not terribly familiar with java script but here is the code below. When executed it opens the...
9
by: loga123 | last post by:
I am using asp .net 2.0. I have a hyperlink asp control on my web page page1.aspx. On clicking this hyper;link, I would like to open page2.aspx (which is in the same web application) in a new IE...
6
by: den 2005 | last post by:
Hi everybody, Question 1: How do you set the values from server-side to a client-side control or how do you execute a javascript function without a button click event? Question 2: How do you...
13
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains...
6
by: mistral | last post by:
what is correct way open a PDF document in new window use hyperlink? I want show images thumbnails linked with PDF files, when click on thumbnail, PDF will be opened in new window. Some of PDF...
1
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.