Subject: ASP on an ASPX page
Posted By: agrzywi Post Date: 1/9/2006 8:28:36 PM
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

Reply By: jbenson001 Reply Date: 1/10/2006 2:55:17 PM
Try using a label in the template.  then set the label.text value = to your app variable..

Just a thought...

Jim




Reply By: planoie Reply Date: 1/11/2006 12:25:24 PM
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. br / br / Instead of the ASP syntax using <% %> you should be able to get away with something like this: br / br / <%# 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
Reply By: agrzywi Reply Date: 1/11/2006 3:39:32 PM
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




Go to topic 38608

Return to index page 397
Return to index page 396
Return to index page 395
Return to index page 394
Return to index page 393
Return to index page 392
Return to index page 391
Return to index page 390
Return to index page 389
Return to index page 388