Wrox Programmer Forums
| 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 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
 
Old January 9th, 2006, 09:28 PM
Registered User
 
Join Date: Jan 2006
Location: Seattle, , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP on an ASPX page

Really I'm a PHP dev and support some legacy ASP, so my terminology might be a bit... obtuse. But my need is to insert a value established in my global.asa file in to a data grid in an ASPX file. I normally reference the variable in ASP files by uttering this:

<% Application("MY_VAR") %>

And this gets resolved to whatever value I've set in the global.asa file; it works great.

Now I have a data grid in an ASPX page that's defined thusly:

<asp:DataGrid id="dgClicks" runat="server" AutoGenerateColumns="False">

And it has lots of BoundColumns and one template column where I need to insert this variable. My attempts to reference the variable like I do on ASP pages just results in a compilation error:

<asp:TemplateColumn HeaderText="Url to Use" ItemStyle-Font-Size="11px"> <ItemTemplate><% Application("MY_VAR") %>
<%# DataBinder.Eval(Container.DataItem, "some_value")%>
</ItemTemplate>
</asp:TemplateColumn>

Produces this error:

Compiler Error Message: CS1002: ; expected

If I use this statement instead I'm able to adjust the error:

<% Application("MY_VAR"); %>

Compiler Error Message: CS0118: 'System.Web.UI.Page.Application' denotes a 'property' where a 'method' was expected

And this makes me think that I don't understand the hierarchy that I'm working with. Is it possible to make the kind of reference that I'm describing? Or is my global.asa file outside of the scope of the ASPX page? Any tips or hints or good questions would be greatly appreciated. Many thanks in advance, AG

 
Old January 10th, 2006, 03:55 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Try using a label in the template. then set the label.text value = to your app variable..

Just a thought...

Jim




 
Old January 11th, 2006, 01:25 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

An ASP global.asa file will be out of the scope of ASPX pages. They operate in different application spaces with different programs. The .NET global.asax is in the scope of ASPX pages.

Instead of the ASP syntax using <% %> you should be able to get away with something like this:

<%# Application["MY_VAR"] %>

Remember, if your page language is C# you'll need to use the right indexing syntax : [n] versus (n). That's probably what causes the first error.

-Peter
 
Old January 11th, 2006, 04:39 PM
Registered User
 
Join Date: Jan 2006
Location: Seattle, , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I really appreciate the input; with a little additional research, I've added these lines to my ASAX file:

<script language="C#" runat="server">
    public void Application_OnStart()
    {
        Application["MY_VAR"] = "my_value";
    }
</script>

(Which compiles without error.) And I now use this in my ASPX page:

<%# Application["MY_VAR"] %>

And what's interesting is that the page takes longer to load with this line in there than without it, but the result is not displayed. It's as if the variable is being evaluated but not drawn--is there anything obvious that I'm missing? (Even outside the datagrid, this variable doesn't resolve.)

Thanks again for setting me down the right track--I hope you're all having great days, AG







Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing values between Asp to Aspx page jayaraj General .NET 2 May 25th, 2004 01:16 AM
How to pass variables from Aspx page to Asp Page jayaraj Classic ASP Basics 2 May 23rd, 2004 06:56 AM
How to pass the variables in Aspx page to Asp Page jayaraj ASP.NET 1.0 and 1.1 Basics 3 May 23rd, 2004 06:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.