Contants and Parameter Name

G

Guest

I have a global class GClass with 2 contants. Both are declared public in the
form:

PUBLIC Const Const1 = "xxx". When I try to use the constant as a default
value (see code excerpt below) the program bombs, but when I use a hardcoded
value it works fine. Any ideas?

Failing Version:

<SelectParameters>
<asp:parameter Name="Catalog" Type="String"
DefaultValue="<%
GClass.Const1 %>" />

Working Version:

<SelectParameters>
<asp:parameter Name="Catalog" Type="String"
DefaultValue="xxx" />

Thanks,
David
 
G

Guest

Unless you have ported the framework to an Atari, I don't really think
that the program bombs. ;)

What error message do you get? Often the error message tells you exactly
what is wrong.
 
V

V

What I meant is that the constant that he is declaring, he should make
it a static variable, because he is trying to access it using the Class
name.

You are right, that you cannot declare a constant static. :)

- V
 
A

Andrew Morton

dwg1011 said:
I have a global class GClass with 2 contants. Both are declared
public in the form:

PUBLIC Const Const1 = "xxx". When I try to use the constant as a
default value (see code excerpt below) the program bombs, but when I
use a hardcoded value it works fine. Any ideas?

Failing Version:

<SelectParameters>
<asp:parameter Name="Catalog"
Type="String"
DefaultValue="<%
GClass.Const1 %>" />

Shouldn't that be:-
<asp:parameter Name="Catalog"
Type="String"
DefaultValue="<%=GClass.Const1 %>" />

?

i.e. no new line splitting the name/value pair to potentially confuse it,
and an equals sign.

Andrew
 
G

Guest

The spacing was just the way it posted. If I am not mistaken the =varname is
"classic" ASP formatting while .net does not require it.

David
 
A

Andrew Morton

The spacing was just the way it posted. If I am not mistaken the
=varname is "classic" ASP formatting while .net does not require it.

Did you try it? I only use code-behind rather than in-line code.

What actually goes wrong? "Bombs" is vague.


*However* I now think it can't work that way. You would have to do it like:-

<%@ Page Language="VB" %>
<script runat="server">
Const const1 as string="xxx"
Sub Page_Load(obj as object, e as eventargs)
Catalog.DefaultValue=const1
End Sub
</script>
[other stuff]
<SelectParameters>
<asp:parameter Id="Catalog" Name="Catalog" Type="String" />

Any use?

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top