Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 20th, 2004, 02:25 PM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default Basic: Calling variable in ASPX from XML

Good afternoon all,

Pardon my newbie question. I am trying to call a variable out of an XML file I created and I am getting the following error:

BC30451: Name 'cfgManager' is not declared

The offending line reads:

<% Response.Write(cfgManager.getSetting("BASE_HREF")) %>

If I place this line in the Page_Load sub (without the <%, %> delimiters of course) within the code-behind it works fine. While this example will not be used in a real-world app I am trying to get my hands around passing information from an XML file to the ASPX file.

Many thanks.




Dolphin Bay, Inc. -- turning visions into eReality(tm) -- West Palm Beach, FL
Website Design, Internet Strategy, Search Engine Marketing

www.DolphinBay.biz
  #2 (permalink)  
Old April 20th, 2004, 06:55 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Can you post what's around that offending line? The context of it would be helpful. Are you saying that the offending line is inside a .xml file?
  #3 (permalink)  
Old April 20th, 2004, 09:09 PM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default

Minus the standard code that VS.Net adds to a webform, the offending line is pretty much all that I added to the file. Below please find the entire aspx file:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="home.aspx.vb" Inherits="test.home"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>home</title>
        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <% Response.Write(cfgManager.getSetting("BASE_HREF")) %> <--- OFFENDING LINE OF CODE
        </form>
    </body>
</HTML>


And here is the content of the XML file, again very basic:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<applicationSettings>
        <BASE_HREF>http://localhost/</BASE_HREF>
</applicationSettings>

The vb file reads the members of an XML file and caches the information. Like I said in my previous email, I know it works when I call the cfgManager class in the code-behind, I just would like to get it to work in the actual ASPX file.

Many thanks for the help.


Dolphin Bay, Inc. -- turning visions into eReality(tm) -- West Palm Beach, FL
Website Design, Internet Strategy, Search Engine Marketing

www.DolphinBay.biz
  #4 (permalink)  
Old April 21st, 2004, 01:50 AM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there ,

You'll need to fully qualify the cfgManager class. That class is not accessible directly in the "Code Before" of your page. Something like this should work:
Code:
<form id="Form1" method="post" runat="server">
  <% Response.Write(test.home.configuration.cfgManager.getSetting("BASE_HREF")) %>
</form>
This code assumes that the cfgManager class lives in the test.home.configuration namespace.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Rob D - Clubbed To Death (kurayamino mix) by The Matrix (Track 4 from the album: The Matrix - Movie Soundtrack)

  #5 (permalink)  
Old April 21st, 2004, 06:15 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Something you should look into is getting away from the ASP style inline code. Instead of an inline <% Response.Write ... %> use one of the many web controls available like a Label or Literal. Then you can set that control's property in the code behind where you don't have the access problem.
  #6 (permalink)  
Old April 21st, 2004, 08:08 AM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default

I would love to get away from using inline code. Do you have any suggestions how I can go about solving this task with an alternate form of coding?

I am trying to use a constant value from an XML file within a javascript code snippet, see below:

var frameRelocate = "<% Response.Write(cfgManager.getSetting("BASE_HREF")) %>";
  if(parent.frames.length == 0) {
    if(document.images) {
      location.replace(frameRelocate);
    } else {
      location = frameRelocate;
    }
  }

As the BASE_HREF value will obviously change based on the domain running the app, I want to incorporate it into an XML constants file, rather than having to manipulate the code or the web.config file for each installation.


Dolphin Bay, Inc. -- turning visions into eReality(tm) -- West Palm Beach, FL
Website Design, Internet Strategy, Search Engine Marketing

www.DolphinBay.biz
  #7 (permalink)  
Old April 21st, 2004, 08:21 AM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

You could use a Literal control embedded in your JavaScript in the ASPX page. That allows you to change its Text property from within the Code Behind page, like this:
Code:
[ASPX Page]
<form id="Form1" method="post" runat="server">
    <script type="text/javascript">
      var frameRelocate = '<asp:literal id="Literal1" runat="Server" />';
    </script>
</form>
And then in your code behind add a declaration for the control:
Code:
protected  System.Web.UI.WebControls.Literal Literal1;
Finally, from within a method in the page class, like Load, you can change the inner text of the Literal control like this:
Code:
Literal1.Text = "Your Base URL Here";
Instead of the hard coded value, you can of course use any method that returns your Base URL.
The JavaScript in your page will now end up like this:
Code:
<script type="text/javascript">
var frameRelocate = 'Your Base URL Here';
</script>
Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Mope by Bloodhound Gang (Track 5 from the album: Hooray for Boobies)

  #8 (permalink)  
Old April 21st, 2004, 08:32 AM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default

Imar,

That did the trick. Thank you for the valuable information regarding the use of literals.

Regards,
Eric


Dolphin Bay, Inc. -- turning visions into eReality(tm) -- West Palm Beach, FL
Website Design, Internet Strategy, Search Engine Marketing

www.DolphinBay.biz
  #9 (permalink)  
Old April 21st, 2004, 08:36 AM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You're welcome.

Like Peter said, using ASP.NET Controls is much better than using "old skool" Response.Write and <% %> constructs. Using the controls allows you to fully separate the code from the design, so you can stay far away from the old spaghetti style coding techniques [not sure if that is good for Italian export, though ;)]
Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Lillies Dying by Curve (Track 5 from the album: Doppelganger)

  #10 (permalink)  
Old April 21st, 2004, 08:42 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I have used that same technique that Imar suggested. Lately, I have been doing something which I find a little less awkward than that. Instead of embedding literals within the javascript itself, I put the whole javascript block in a literal and use replacement tokens in the JS code:
<asp:literal id="Literal1" runat="Server">
   <script type="text/javascript">
      var frameRelocate = '[%FRAMERELOCATE%]';
      var intSomeInteger = [%ANOTHERVAR%];
   </script>
</asp:literal>

In the code-behind, I only need to have one class instance of a literal control:

   Protected Literal1 As System.Web.UI.WebControls.Literal

Then in the page load, or wherever is appropriate, I replace the tokens with real values:

Literal1.Text = Literal1.Text.Replace("[%FRAMERELOCATE%]", strFrameRelocate)
Literal1.Text = Literal1.Text.Replace("[%ANOTHERVAR%]", intMyInteger)

If you have to put a lot of server side values into client side script, I find this to be a little cleaner and easier way to deal with the values.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling Class within ASPX file kingroon ASP.NET 2.0 Basics 3 July 9th, 2008 07:43 AM
Calling c# String variable help simonlm C# 2005 0 May 25th, 2007 04:01 AM
Calling codebehind C# function from aspx page ravindrasingh77 BOOK: ASP.NET Website Programming Problem-Design-Solution 2 March 16th, 2005 12:08 AM
Calling procedure of User Control from aspx file vskumar VB.NET 1 February 15th, 2005 11:17 AM
Calling crystal subreport in Visual Basic 6 maryjanedt08 VB How-To 2 December 3rd, 2004 06:01 AM



All times are GMT -4. The time now is 05:43 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.