Open Window with Javascript from WebUserControl and return values

Discussion in 'ASP .Net Building Controls' started by Jorge Ponte, Dec 20, 2004.

  1. Jorge Ponte

    Jorge Ponte Guest

    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
    Jorge Ponte, Dec 20, 2004
    #1
    1. Advertising

  2. "Jorge Ponte" <> wrote in message
    news:...
    > 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...


    If this is the problem, then the solution is to find the dynamic id by
    referencing textbox.ClientID. Store that in your javascript somewhere or
    pass it as a parameter to a javascript function, and you should be able to
    pass it to your child form, which could then use it to set the value back on
    the parent form.

    If this works, please post the resulting code, as it would be a good example
    for others.

    John Saunders
    John Saunders, Dec 20, 2004
    #2
    1. Advertising

  3. Jorge Ponte

    Jorge Ponte Guest

    Re: Open Window with Javascript from WebUserControl and return val

    I think thats the problem but I cant get it to work, even passing textbox.ID
    or textbox.UniqueID...the popup dont know where to put the text. I'm trying
    to do it with sessions but with sessions I have to refresh the "main" page so
    it can read the session...can this be possible?how?




    "John Saunders" wrote:

    > "Jorge Ponte" <> wrote in message
    > news:...
    > > 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...

    >
    > If this is the problem, then the solution is to find the dynamic id by
    > referencing textbox.ClientID. Store that in your javascript somewhere or
    > pass it as a parameter to a javascript function, and you should be able to
    > pass it to your child form, which could then use it to set the value back on
    > the parent form.
    >
    > If this works, please post the resulting code, as it would be a good example
    > for others.
    >
    > John Saunders
    >
    >
    >
    Jorge Ponte, Dec 21, 2004
    #3
  4. Jorge Ponte

    Analisa Guest

    Re: Open Window with Javascript from WebUserControl and return val

    Try with document.forms[0].textboxname.value
    --
    POST BY: http://www.dotNET.us - Need .NET? Just ask, Please dotNET.us
    Analisa, Jan 17, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BTHN
    Replies:
    0
    Views:
    470
  2. Arun

    WebUserControl and JavaScript

    Arun, Jul 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,777
  3. =?Utf-8?B?Sm9yZ2UgUG9udGU=?=

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

    =?Utf-8?B?Sm9yZ2UgUG9udGU=?=, Dec 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,837
    Karl Seguin
    Dec 20, 2004
  4. Andy B
    Replies:
    1
    Views:
    335
    Munna
    Jun 7, 2008
  5. jgrant

    WebUserControl/ascx Properties window

    jgrant, Feb 15, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    179
    jgrant
    Feb 15, 2006
Loading...

Share This Page