Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Passing data from popout window to parent window


Message #1 by "Tom Zhang" <tzhang@p...> on Fri, 13 Dec 2002 16:25:56
Example code below opens a popup and also populates a target control
based on type

Code to create a dynamic button to launch an input popup with javascript
following.

Dim sControlUrl As String = "'InputCtrlHost.aspx?CtrlType=" &
arrParams(2) & "&TargetControl=" & txtBox.ID & "&Params=" &
sControlParams & "'"

        Dim btnEntry As New HtmlButton()
        btnEntry.InnerHtml = "<B>:</B>"

        Dim sJavaFunction As String = "CenteredPopup(" & sControlUrl &
",'Medication_Comments'," & sWidth & "," & sHeight & ");"
        
        btnEntry.Attributes.Add("onclick", sJavaFunction)


Code from input control host, it just loads a user control based on type
passed.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        'This page loads any required pop-up input control based
        'on ControlId passed
        Dim iCtrId = Request.QueryString("CtrlType")

        Select Case iCtrId
            Case 1
                Dim ctlControl As Control
                ctlControl = LoadControl("Keypad.ascx")
                ctlHolder.Controls.Add(ctlControl)
            Case 2, 3, 4
                Dim ctlControl As Control
                ctlControl = LoadControl("TimeStamp.ascx")
                ctlHolder.Controls.Add(ctlControl)

            Case 5
                Dim ctlControl As Control
                ctlControl = LoadControl("TextInputControl.ascx")
                ctlHolder.Controls.Add(ctlControl)
            Case 6
                Dim ctlControl As Control
                ctlControl = LoadControl("DOB.ascx")
                ctlHolder.Controls.Add(ctlControl)

            Case 7
                Dim ctlControl As Control
                ctlControl = LoadControl("HeightControl.ascx")
                ctlHolder.Controls.Add(ctlControl)
        End Select

    End Sub
    
Code that is run from keypad control to populate a textbox

Dim sb As New System.Text.StringBuilder()
        sb.Append("<SCRIPT type='text/javascript'>")
        sb.Append("opener.focus();")
        sb.Append("opener.setTextBoxValue('" & sTargetControl & "'," &
txtValue.Text & ");")
        sb.Append("opener.setCtrlFocus('" & sTargetControl & "');")
        sb.Append("window.close();")
        sb.Append("</SCRIPT>")
        Page.RegisterClientScriptBlock("targetopener", sb.ToString)

//**********************************************************************
*****//
//Control Launch functions
var inputwindow;
//Launches the proper input user control 
function CenteredPopup(mypage,myname,w,h,features) {
  if (inputwindow) inputwindow.close();
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  inputwindow = window.open(mypage,myname,settings);
  inputwindow.window.focus();
}


//Set control value functions
//Set a textbox's value
function setTextBoxValue(controlid,newvalue) {
  var elem
  for(i=0;i<document.forms[0].elements.length;i++) {
    elem=document.forms[0].elements[i]
    if (elem.name.indexOf(controlid)!=-1) {
      elem.value = newvalue
      return true
    }
  }
}


//Set the value of a dropdown box
function setDropdownValue(controlid,newvalue){
  for(i=0;i<document.forms[0].elements.length;i++) {
    elemsourc=document.forms[0].elements[i]
    if (elemsourc.name.indexOf(controlid)!=-1) {
	   elemsourc.options[newvalue].selected = true;
      return true
    }
  }
}
   

//Give a contorl focus after setting its value
function setCtrlFocus(controlid) {
  var elem
  for(i=0;i<document.forms[0].elements.length;i++) {
    elem=document.forms[0].elements[i]
    if (elem.name.indexOf(controlid)!=-1) {
      elem.focus();
      elem.select();
      return true
    }
  }
}

//Sets all target checkbox values to false
function setMultipleCkValues(ckTargetIds)
{
var col_array= ckTargetIds.split(",");
var index=0;
while (index < col_array.length)
 {
 for(i=0;i<document.forms[0].elements.length;i++) {
    elemsourc=document.forms[0].elements[i]
    if (elemsourc.name.indexOf(col_array[index])!=-1) {
	  elemsourc.checked = false
	 	 	 
    }
  }
 index+=1;
  }
}

//Sets a checkbox's value to true
function setckBox(targetid) {
  var elemsourc
 
  for(i=0;i<document.forms[0].elements.length;i++) {
    elemsourc=document.forms[0].elements[i]
    if (elemsourc.name.indexOf(targetid)!=-1) {
	  elemsourc.checked = true
	 	 	 
    }
  }
}

//Closes all launched input control windows
function CloseInputControls() {
  if (inputwindow && inputwindow.open && !inputwindow.closed)
inputwindow.close();
}

-----Original Message-----
From: Tom Zhang [mailto:tzhang@p...] 
Sent: Friday, December 13, 2002 4:26 PM
To: ASPX_Professional
Subject: [aspx_professional] Passing data from popout window to parent
window

Hi,
It is common to use a popout window to collect data and then fill out
one 
or more html text boxes with the collected data on parent window upon 
closing the popout window using javascript (window.opener...) in asp 
programming. Popout calendar is a good example. 

Unfortunately, I could not figure out how to do this in asp.net. I have 
searched a lot of sites but did not find good information. Can anyone 
give me some directions. Some sample code or an url would be a great
help.

Thanks in advance? 
Tom



  Return to Index