PDA

Click to See Complete Forum and Search --> : Controlling Parent TextBox


jesus4u
May 30th, 2003, 12:29 PM
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.


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

Cander
May 30th, 2003, 01:32 PM
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.

jesus4u
May 30th, 2003, 01:40 PM
REALLY? Well try this on for size! :) It works!!!!!!!!!


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

Cander
May 30th, 2003, 01:50 PM
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.

jesus4u
May 30th, 2003, 01:52 PM
well it is weird how I am using the code behind to fire off client side code :p

Cander
May 30th, 2003, 01:54 PM
you are'nt. It is just adding the javascript to the output produced by the server. It doesnt run until it hits the client

jesus4u
May 30th, 2003, 01:55 PM
:cool:

Cander
May 30th, 2003, 01:57 PM
Its all good anyway. It works!:D