?
Solved

Big problem: passing a field value from a .htm page to an asp.net page (and back)

Posted on 2003-03-04
23
Medium Priority
?
480 Views
Last Modified: 2012-05-04
Hello Guys, I'm in deep trouble, I need to finish this by tomorrow and I just crashed into a big wall.

Recently I've been assigned the task of developing an asp.net page that the users of another web aplication (running on a different server that can't execute asp.net pages) will open as a floating window and that will let them choose two options from two dropdownlist boxes which are populated from a SQL Server 2000 database, using the value of a field that's in the parent non-asp web application as the key for the SELECT statement. When the user picks their desired options they must press a button that will assign those two values to two fields back in the parent web application and then close the floating asp.net page window. I must mention that the parent web application is on a Domino/Notes server, that's why I'm developing this page to avoid the burden of accessing the SQL Server database directly from the Notes Web application.

My first idea seemed simple, use a "window.open" javascript instruction in the Parent web application to open the Asp.net page, then in the asp.net page use a "window.opener.document ..." to retrieve the value of the key field from the parent web aplication, proceed to populate the drowdownlist boxes from the SQL server database (using the key field in the SELECT statement), and then when the user clicks a button use a "window.opener.document ..." again to send back the picked options to the parent web application, close the asp.net floating window and that's it.

I've already programed the Asp.net page, it access the database with no trouble and let's you pick the values from the dropdownlist boxes. Currently I'm assiging the value of the key field directly (for developing purposes).

The problem now is that I'm having problems passing the key value from the parent web app page to the asp.net page (and of course passing the choosen values back to the R5 page).

For testing purposes I made two simple .htm pages (one represents the parent page, the other one the floating window), those pages have some fields and the javascript code that makes the transfer and it works with no trouble.

I've tried to insert the Javascript code into the asp.net page and when it loads I get "window.document.forms.0.Cedula.value is null or not an object" (don't know why it reports the "0" without the brackets [] 'cause they are in the code)

Also I must mention that the parent web app and the Asp.net page are on different servers( the first one in a Lotus/Domino server the latter on a IIS Win2k server).

Any lights that you can give me will be very welcomed, if you think I should do this in other way let me know, from what I now since the parent web app is a Domino/Notes application I must use javascript to transfer the values between it and the Asp.net floating page, I don't know if it's possible to pass the value in the URL that calls the floating asp.net page, and if that's possible I don't know how I would handle that in the asp.net page.
Thanks in advance

PalmDrac
0
Comment
Question by:PalmDrac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
  • 5
  • +1
23 Comments
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 800 total points
ID: 8066784
I think that the floating window needs to be called from the window that will ultimately receive the values. That is because you will need to use the window.opener to catch the value from the popup. Something like this:

*********
parent.htm
**********

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function openWindow(){
     var winChild=window.open('child.htm','winChild','width=100,height=100')
}

//-->
</SCRIPT>
</HEAD>
<BODY onLoad="javascript:openWindow()">

<FORM action="" method=POST id=form1 name=form1>
Test Value<INPUT type="text" id=text1 name=text1>
</FORM>
</BODY>
</HTML>


**********
child.htm
**********

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function processAnswer(strValue){
window.opener.document.forms[0].text1.value=strValue
window.close();
}
//-->
</SCRIPT>
</HEAD>
<BODY>

<FORM action="" method=POST id=form1 name=form1>
Yes<INPUT type="radio"  name=radio1 value="Yes" onClick="javascript:processAnswer(this.value)"><br>
No<INPUT type="radio"  name=radio1 value="No" onClick="javascript:processAnswer(this.value)"><br>
</FORM>
</BODY>
</HTML>
0
 

Author Comment

by:PalmDrac
ID: 8066828
Frits... yes, the floating window it's been opened from the page that will receive the values, I'm using two pages:

parent.htm : the page in the domino server that will receive the value

dbacess.aspx : the asp.net floating page that will access the database and will send back the chosen values to parent.htm

Remember that dbaccess.aspx is an asp.net page, your code is for two .htm pages.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8066879
That's the point that I am making--the floating window has to be spawned from the page that will recieve the value. So, you will need to do something like this on the parent.htm:

var winChild=window.open(dbacess.aspx','winChild','width=100,height=100')


and have this on your dbacess.aspx page:


window.opener.document.forms[0].text1.value=strValue

Fritz the Blank
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8067068
have you tried:

window.parent.document.FormName.1stKeyField.value=window.document.FormName.1stKeyChoice.value;

in the new window script??

i did the same thing myself for a login feature and it worked.. but i'm not sure if that's exactly how i used it... but it has something to do with .parent

Hope this helps...

MaxOvrdrv2
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8067081
where window.parent would be the one that would receive the choices from the drop-down of the new page...

MaxOvrdrv2
0
 

Author Comment

by:PalmDrac
ID: 8067086
Fritz.... yup that's what I've done, it's explained in my post, with that method asp.net reports me the following error:

"window.document.forms.0.Cedula.value is null or not an object" (don't know why it reports the "0" without the brackets [] 'cause they are in the code, the same happens with the window.opener ....)

The other shortcoming of that method is that to use window.opener the pages needs to be in the same server, and that's impossible for me since the parent page is on a domino server, and the asp.net child page is on an IIS server.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8067140
I don't know that you can pass values from one domain to another that way.... That may be why this is failing.

You might want to do replace forms[0] with the actual form name just in case that is the issue.

Fritz the Blank
0
 
LVL 1

Expert Comment

by:retronaut
ID: 8067296
the code that fritz the bank gave you works fine.  It does not matter if it is a htm page as javascript operates on the client.

try using a button to open the child window in the parent form and pass the value using a simple querystring:

<HTML><HEAD><title>Parent</title>
</HEAD>
<BODY>
<SCRIPT LANGUAGE=javascript>
<!--
function openWindow(){
     var childurl = ( 'child.asp?val=' + document.form1.text1.value );
     var winChild = window.open( childurl , 'winChild');
}
//-->
</SCRIPT>
</HEAD>

<FORM action="" method=POST id=form1 name=form1>
to child <INPUT type="text" id=text1 name=text1>
<BR><input type=button name=open value=OpenChild onclick="javascript:openWindow()">
<BR><BR>from child <INPUT type="text" id=text2 name=text2>
</FORM>
</BODY>
</HTML>


and


<HTML><HEAD><title>Child</title>

<SCRIPT LANGUAGE=javascript>
<!--
function processAnswer(strValue){
window.opener.document.form1.text2.value = (strValue);
alert (strValue);
window.close ();
}
//-->
</SCRIPT>

</HEAD>

<BODY>

<FORM action="" method=POST id=form1 name=form1>
from parent <input type=txt name=from_parent value="<%=request.querystring.item("val")%>">
<BR><BR>Send Yes <INPUT type="radio" name=radio1 value="Yes" onClick="javascript:processAnswer(this.value)">
<BR>Send No <INPUT type="radio" name=radio1 value="No" onClick="javascript:processAnswer(this.value)"><br>
</FORM>

</BODY>
</HTML>
0
 
LVL 1

Expert Comment

by:retronaut
ID: 8067360
oopps,

I have set this up with one page on our test server and the other on our production box and I get a js error: "access denied" when i try to pass the values back to the parent - interesting.

You may have to go from the parent to the child as a get or post action on the parent form.

The child would then pass the selected value back by calling the parent again using a get or post action.

The pop-up appear to be a problem, people may also be running a pop-up stopper.

0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8067375
yes.... you must make sure (in order to complete this task) that sharing options on the dominos box are set so that YOUR server has access to theirs...

Maxovrdrv2
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8067429
So to reiterate, try fully qualifying the path for the form name, and create a simple test passing the value from one domain to another because that may not be permissable.

Fritz the Blank
0
 

Author Comment

by:PalmDrac
ID: 8069257
Hi guys.... I've managed to get part of the code working in the page but I still need help to make it actually do the job:

From parent(.htm) to child(.aspx) I'm using a querystring like this:

<SCRIPT LANGUAGE="JavaScript">
<!--
function openWindow(){
    var childurl = ( 'http://incubus/asp/dbase4.aspx?clave=' + document.formapadre.Cedula.value );
    var winChild = window.open(childurl, 'winChild', 'status,scrollbars,resizable,dependent,width=350,height=350,left=10,top=10');
}
// -->
</SCRIPT>

Then on the child aspx page I'm using a request.params to fill a text box with the value:

Sub Page_Load(Sender As Object, E As EventArgs)
    txtClave.Text = Request.Params("clave")

So now I have the key value in the txtClave textbox. What I need to do know is to "append" the value of txtClave into my SELECT string so it will return what I need from the DB, I've tried this but it didn't work:

Sub BindData()
    Dim oConn As SqlConnection
    Dim oCmd As SqlCommand
    Dim oDR As SqlDataReader
    Dim provId As Integer
    provId = txtClave.text    <------------- this causes an error

    Dim sConn As String
    Dim sSQL As String

    sConn = "server='localhost'; user id='sa'; password='xxxxxx'; Database='mydatabase'"
    sSQL = "select plan_id,plan_nombre from t_planes where proveedor_id = " & provId    <------- I need that value here

    oConn = New SqlConnection(sConn)
    oConn.Open()


I must say that this is my first Asp.net page, although I've had a couple of past experiences with classic Asp in the past. I'm armed with two books to help me in my task, Asp.net Unleashed and Asp.net Database Programming Weekend Crash Course.

Another issue I have is this. In my Asp.net child page I've created a javascript routine that process the selected options, send them back to the parent page and closes the child aspx window, like this:

<SCRIPT LANGUAGE=javascript>
<!--
function processAnswer(strPlan,strModalidad){
window.opener.document.formapadre.NombrePlan.value = (strPlan);
window.opener.document.formapadre.ModalidadPlan.value = (strModalidad);
window.close ();
}
//-->
</SCRIPT>

<html>
<head>
</head>
<body>
    <form id="myForm" name="formahija" runat="server">
        Cédula del Proveedor:<asp:TextBox id="txtClave" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:DropDownList id="lstPlanes" runat="server" name="planes" ONSELECTEDINDEXCHANGED="lstPlanes_OnChange" autopostback="True"></asp:DropDownList>
        <br />
        <br />
        <asp:DropDownList id="lstModalidad" runat="server" name="modalidad" autopostback="True" Visible="False"></asp:DropDownList>
        <br />
        <br />
        <input type="button" value="Button" onclick="javascript:processAnswer(I need the value of the dropdownlists "planes" and "modalidad" here)">
        <asp:Button id="btnNotes" runat="server" Visible="False" Text="Escoger"></asp:Button>
    </form>
</body>
</html>

I'm having problem with that ONCLICK event, in which I need the value of the two dropdownlist boxes so it can be process by the processAnswer routine.

Thanks in advance for your help
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8071678
ah... ok... well...

try this:

provId=document.FormNameIfThereIsOne.txtClave.value

this type of referencing also works in VBScript & ASP you know...

MaxOvrdrv2
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8072422
Let's take a step back (I know that is a pain in the butt):

What happens if you do this:

for each objField in Request.Params("clave")
  Response.write(objField & ": " & Request.Params("clave") & "<P>")
next

Fritz the Blank
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8072433
I am just trying to make certain that you get the value that you think you are getting. Is there any reason that you are not using Request.QueryString (excuse my.NET ignorance)?

Fritz the Blank
0
 

Author Comment

by:PalmDrac
ID: 8072434
Hello guys...

Well after much hard work I got it done on time, I was up until 4am working and I had to get up at 7am, but the thing is working and I just showed it to my boss and everything went fine. THANKS GUYS FOR ALL YOUR KIND HELP. I will take Frit's comment as the answer since he gave us the basic concept, although I'd like to thank Max and Retronaut for your collaboration to the code.

The only shortcoming that I haven't been able to solve is that both pages must be in the same server, otherwise an "Acess is denied" javascript error is reported when pressing the button in the child page that sends the values back to the parent page. Thankfully for the sake of this "Proof of Concept" that I had to show up to my boss today that wasn't a problem, but I need to solve that issue for the next phase "Testing with development data". One of the things I think I can try is to use a query string to send the info back, the same way I used it to send the info from parent to child. The problem is that the Domino server might not like that :(, anyway if you have any additional comment on that one please let me now, I think I'll post that issue as a question in the javascript forum.

BTW... the data access issues that I posted on my previous comment only required a revision of the Ado.net chapter of my Asp.net Unleashed book, everything was there (the sql parameters thing)

Here are snippets of my code so it can help other people in the future:

-------- parent.htm ------- (this represents the NotesR5 page in the Domino server, this one will call the asp.net page)

<HTML>
<HEAD>
<title>Pagina Lotus Notes R5</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
function openWindow(){
    var childurl = ( 'http://enigma/asp/dbase5.aspx?clave=' + document.formapadre.Cedula.value );
    var winChild = window.open(childurl, 'winChild', 'status,scrollbars,resizable,dependent,width=350,height=350,left=10,top=10');
}
// -->
</SCRIPT>


</HEAD>
<BODY TEXT="000000" BGCOLOR="FFFFFF">

<FORM METHOD=post NAME="formapadre">

<center><b>Esto es una pagina Notes R5</b></center><br><br>
<B><FONT SIZE=2 FACE="Verdana">Cedula</FONT></B>
<INPUT NAME="Cedula" VALUE=""><br><br>

<B><FONT SIZE=2 FACE="Verdana">Nombre del Plan</FONT></B>
<INPUT NAME="NombrePlan" VALUE=""><br><br>

<B><FONT SIZE=2 FACE="Verdana">Modalidad del Plan</FONT></B>
<INPUT NAME="ModalidadPlan" VALUE=""><br><br>
<INPUT TYPE=button onClick="javascript:openWindow();" VALUE="Buscar Plan">
<INPUT TYPE=reset VALUE="Vaciar Campos">


</BODY>
</HTML>


-------- end of parent.htm --------------------------

--------- dbase5.aspx -------- The child asp.net page that will do the database connection and get the data based on the value of the key field back in parent.htm -----------


<%@ Page Language="VB" Debug="True" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

    Sub BindData()
        Dim oConn As SqlConnection
        Dim oCmd As SqlCommand
        Dim oDR As SqlDataReader
   
        Dim sConn As String
        Dim sSQL As String
   
        sConn = "server='localhost'; user id='sa'; password='xxxxxx'; Database='MyDb'"
        sSQL = "select plan_id,plan_nombre from t_planes where proveedor_id = (select proveedor_id from t_proveedores where proveedor_cedula = @proveedorcedula)"
   
        oConn = New SqlConnection(sConn)
        oCmd = New SqlCommand(sSQL, oConn)
        oCmd.Parameters.Add("@proveedorcedula",SqlDbType.Varchar).Value = txtClave.Text
   
        oConn.Open()
        oDR = oCmd.ExecuteReader()
   
        lstPlanes.DataSource = oDR
        lstPlanes.DataTextField = "plan_nombre"
        lstPlanes.DataValueField = "plan_id"
        lstPlanes.DataBind()
        lstPlanes.Items.Insert(0, New ListItem("<-- Selecciona un Plan -->", ""))
   
        oConn.Close
        oDR.Close
        oConn = Nothing
        oDR = Nothing
    End Sub
   
    Public Sub lstPlanes_OnChange(Sender As Object, E As EventArgs)
        Dim oConn As SqlConnection
        Dim oCmd As SqlCommand
        Dim oDR As SqlDataReader
   
        Dim sConn As String
        Dim sSQL As String
        Dim planId As Integer
        planId = lstPlanes.SelectedItem.Value
   
        sConn = "server='localhost'; user id='sa'; password='xxxxx'; Database='MyDb'"
        sSQL = "select modalidad_id,modalidad_nombre from t_modalidad where plan_id = " & planId
        oConn = New SqlConnection(sConn)
        oConn.Open()
   
        oCmd = New SqlCommand(sSQL, oConn)
        oDR = oCmd.ExecuteReader()
   
        lstModalidad.DataSource = oDR
   
        lstModalidad.DataSource = oDR
        lstModalidad.DataTextField = "modalidad_nombre"
        lstModalidad.DataValueField = "modalidad_id"
   
        lstModalidad.DataBind()
        lstModalidad.Items.Insert(0, New ListItem("<-- Selecciona una Modalidad -->", ""))
   
        oConn.Close
        oConn = Nothing
        oDR.Close
        oDR = Nothing
   
        lstModalidad.Visible = True
   
   
    End Sub
   
    Sub Page_Load(Sender As Object, E As EventArgs)
        txtClave.Text = Request.Params("clave")
        If Not Page.IsPostback() Then
            BindData()
        End If
   
    End Sub

</script>
<html>
<head>
<title>Pagina Asp.net</title>

<script language="javascript">
<!--
function processAnswer(strPlan,strModalidad){
window.opener.document.forms[0].NombrePlan.value = (strPlan);
window.opener.document.forms[0].ModalidadPlan.value = (strModalidad);
top.close ();
}
//-->
</script>

</head>
<body>
    <center><b>Esto es una pagina Asp.net conectandose a SQL Server</b>
    </center>
    <br />
    <br />
    <br />
    <form id="formahija" runat="server">
        Cidula del Proveedor:<asp:TextBox id="txtClave" runat="server" name="txtClave"></asp:TextBox>
        <br />
        <br />
        <asp:DropDownList id="lstPlanes" runat="server" ONSELECTEDINDEXCHANGED="lstPlanes_OnChange" autopostback="True"></asp:DropDownList>
        <br />
        <br />
        <asp:DropDownList id="lstModalidad" runat="server" autopostback="True" Visible="False"></asp:DropDownList>
        <br />
        <br />
        <input onclick="javascript:processAnswer(window.document.forms[0].lstPlanes.options[window.document.forms[0].lstPlanes.selectedIndex].text,window.document.forms[0].lstModalidad.options[window.document.forms[0].lstModalidad.selectedIndex].text);" type="button" value="Seleccionar" />
    </form>
</body>
</html>
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8072491
see... the way it is being processed is that the address of your server is requestiong something resident on the domino server (i.e.: a server/client variable stored on a page) and therefore... you need to have the proper rights on the domino server (or rather... your server must have the rights) to be able to access it...

it's the same thing as if you were trying to reference a picture being held on the hard-drive of the client... every time it would say Access is Denied... unless you had the proper rights...

MaxOvrdrv2
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8072498
Yeah, that's what I was saying about passing accross domains. I have run into that before.

I am glad that things went well,

Fritz the Blank
0
 

Author Comment

by:PalmDrac
ID: 8072553
Hey Max... do u know how could I set up the domino box to avoid the access is denied message?, in my current testing environment I have administrator access to both servers.

FYI... the domino server is running on a Win2k Advanced Server box.
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8072568
yeah... it's a bit tricky to get working...

MaxOvrdrv2
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8072585
well... i'm not really sure how to get it to work... on my web server at home.. i just gave myself the rights to my desktop PC and was able to access anything from then on...

but other than that.. that's pretty much all i know...

i had a javascript that would let someone enter a filename for a picture and then it would try to display that picture... yet when the picture was not a url but a file located elsewhere than the server... i kept getting access denied... but after i gave myself the rights through the IIS, i could do anything...

MaxOvrdrv2
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8072589
For access folders and files, see:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q184566

Fritz the Blank
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8072651
thanks fritz...

MaxOvrdrv2
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question