 |
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 20th, 2004, 02:25 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 20th, 2004, 06:55 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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?
|
|

April 20th, 2004, 09:09 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 21st, 2004, 01:50 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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)
|
|

April 21st, 2004, 06:15 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|

April 21st, 2004, 08:08 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 21st, 2004, 08:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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)
|
|

April 21st, 2004, 08:32 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 21st, 2004, 08:36 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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)
|
|

April 21st, 2004, 08:42 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|
 |