Solved

ASP.Net and Javascript variables

Posted on 2004-09-17
2
259 Views
Last Modified: 2010-05-18
Here is my code:
---
<%@ Page Language="VB" %>
<Script Runat="server">            
      Sub Page_load()
            Dim strCity As String
            Dim strState As String
            Dim intZip As Integer
            
            strCity = "Tampa"
            strState = "Fl"
            intZip = 33607
      
            lblCity.Text = strCity
            lblState.Text = strState
            lblZip.Text = intZip
      End Sub
</Script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>window_page1.aspx</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
      leftPos = 0
      if (screen) {
            leftPos = screen.width-750
      }
      
      function OpenWindow()
      {
       window.open("window_page2.aspx?City=<%= strCity %>&State=<%= strState %>&Zip=<%= intZip %>", "newWin", "width=550,height=500,left="+leftPos+",top=0,statusbar=yes,resizable=yes,scrollbars=yes,status=yes")
      }
</SCRIPT>
</head>
<body>
<a href="JavaScript:OpenWindow()">Open Window</a>
<p>
<b>Variables to be passed:</b><br>
City: <asp:label id="lblCity" runat="server" Text=""/>
<br />
State: <asp:label id="lblState" runat="server" Text=""/>
<br />
Zip: <asp:label id="lblZip" runat="server" Text=""/>
<br />
</body>
</html>
---

When I try and run this I get the following error:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'intZip' is not declared.
Source Error: Line 31:        window.open("window_page2.aspx?City=<%= strCity %>&State=<%= strState %>&Zip=<%= intZip %>", "newWin", "width=550,height=500,left="+leftPos+",top=0,statusbar=yes,resizable=yes,scrollbars=yes,status=yes")


Any ideas?
0
Comment
Question by:matthersjr
2 Comments
 
LVL 17

Accepted Solution

by:
AerosSaga earned 500 total points
ID: 12088549
try it this way:
window.open("window_page2.aspx?City=<%= Me.lblcity.text %>&State=<%= Me.lblState.text %>&Zip=<%= Me.lblZip.Text %>", "newWin", "width=550,height=500,left="+leftPos+",top=0,statusbar=yes,resizable=yes,scrollbars=yes,status=yes")

Regards,

Aeros
0
 
LVL 9

Expert Comment

by:hismightiness
ID: 12088579
Have you tried using literal controls instread of the Response.Write?  It looks like the code runs, then the page is rendering, but in the mean time the variables have already been processed in a past event (page load), and the variable scope is lost.  You could either use literal controls, or even better have a couple of functions written to return your variables and call them like this:

<%@ Page Language="VB" %>
<Script Runat="server">          
     Dim strCity As String
     Dim strState As String
     Dim intZip As Integer

     Sub Page_load()
          strCity = "Tampa"
          strState = "Fl"
          intZip = 33607
     
          lblCity.Text = strCity
          lblState.Text = strState
          lblZip.Text = intZip
     End Sub

     Public Function rtnCity() as String
          return strCity
     End Function

     Public Function rtnState() as String
          return strState
     End Function

     Public Function rtnZip() as String
          return CType(strZip, String)
     End Function
</Script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>window_page1.aspx</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
     leftPos = 0
     if (screen) {
          leftPos = screen.width-750
     }
     
     function OpenWindow()
     {
      window.open("window_page2.aspx?City=<%= rtnCity() %>&State=<%= rtnState() %>&Zip=<%= rtnZip() %>", "newWin", "width=550,height=500,left="+leftPos+",top=0,statusbar=yes,resizable=yes,scrollbars=yes,status=yes")
     }
</SCRIPT>
</head>
<body>
<a href="JavaScript:OpenWindow()">Open Window</a>
<p>
<b>Variables to be passed:</b><br>
City: <asp:label id="lblCity" runat="server" Text=""/>
<br />
State: <asp:label id="lblState" runat="server" Text=""/>
<br />
Zip: <asp:label id="lblZip" runat="server" Text=""/>
<br />
</body>
</html>
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now