Results 1 to 8 of 8

Thread: Controlling Parent TextBox

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Question Controlling Parent TextBox

    Page A pops a new window called Page B.

    How would I set the text value of Page A's TextBox from Page B's button click event?

    I want to do this all on the code behind.

    I tried doing this on Page B but to no avail.

    Code:
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            Dim myControl1 As Control = FindControl("Calendar1")
            Dim myControl2 As Control = myControl1.Parent()
            Dim parent As Control = Page.Parent
            Response.Write(myControl2.ID)
        End Sub

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    your only option is to set a session variable on B, then also run some javascript that will make page A postback to itself, then populate the textbox via the set session variable. The way are thinking just is not going to be possible.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    REALLY? Well try this on for size! It works!!!!!!!!!

    Code:
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim id As String = Request.QueryString("id")
            Dim script As String
            If id = "1" Then
                script = "<script language=""JavaScript"">" & vbCrLf & _
                            "function SendMeBack(x)" & _
                            "{window.opener.Form1.txtStartDate.value=x}" & _
                            vbCrLf & "<" & "/script>"
    
            Else
                script = "<script language=""JavaScript"">" & vbCrLf & _
                            "function SendMeBack(x)" & _
                            "{window.opener.Form1.txtEndDate.value=x}" & _
                            vbCrLf & "<" & "/script>"
            End If
            RegisterStartupScript("SendBack", script)
        End Sub
    
        Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
            Call TheRegScript(Calendar1.SelectedDate)
        End Sub
    
        Private Sub TheRegScript(ByVal theD As String)
            RegisterStartupScript("Send", "<script language=""JavaScript"">" & vbCrLf & _
                   "SendMeBack('" & Calendar1.SelectedDate & "')" & _
                   vbCrLf & "<" & "/script>")
        End Sub
    Last edited by jesus4u; May 30th, 2003 at 01:45 PM.

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    oh..no I knew you can do all that with the window.opener object in the javascript DOM. but I thought you were trying to do it all server side.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    well it is weird how I am using the code behind to fire off client side code

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you are'nt. It is just adding the javascript to the output produced by the server. It doesnt run until it hits the client
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Its all good anyway. It works!
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width