Partial Classes, .Net 2.0 and Custom Attributes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I had an aspx pag in .Net 1.1 with a label on it. As such I had a code
behind page with a declaration for that label.

When I convert to Asp.Net 2.0 the code behind is converted to a partial
class and the declaration for the label is removed. This is what I expected
to happen and I understand why it has happened.

The problem I have is that I had added a custom attribute to my label
declaration which I use to handle localization. e.g.

[Localize]
protected System.Web.UI.WebControls.Label lScreenTitle;

Since that declaration has been removed, so has the custom attribute.

My question is, how do you add a custom attribute to a control on an aspx
page in Asp.Net 2.0 given that you no longer have access to the control's
declaration in the code-behind file?

Thanks,

Julian Jelfs.
 
Thanks for the response. I have looked into the Asp 2 localization model and
it doesn't quite do what I want it to.

It seems like a bit of a problem that it is impossible to add an attribute
to a control added declaratively in design view. I can't believe there's no
way to do it. I do want to do things the 2005 way in every other regard
because it's easier and better.

Brock Allen said:
If you need to add a custom attribute to the field, then don't use partial
classes and the new CodeFile directive. I think you're going to have a struggle
though, as the new VS.NET model doesn't want to do things the old way :)

BTW, since your attribute is called [Localize] I'm wondering if the new localization
model in 2.0 will suit your needs:

http://beta.asp.net/QUICKSTART/aspnet/doc/localization/default.aspx

-Brock
DevelopMentor
http://staff.develop.com/ballen


Hi,

I had an aspx pag in .Net 1.1 with a label on it. As such I had a code
behind page with a declaration for that label.

When I convert to Asp.Net 2.0 the code behind is converted to a
partial class and the declaration for the label is removed. This is
what I expected to happen and I understand why it has happened.

The problem I have is that I had added a custom attribute to my label
declaration which I use to handle localization. e.g.

[Localize]
protected System.Web.UI.WebControls.Label lScreenTitle;
Since that declaration has been removed, so has the custom attribute.

My question is, how do you add a custom attribute to a control on an
aspx page in Asp.Net 2.0 given that you no longer have access to the
control's declaration in the code-behind file?

Thanks,

Julian Jelfs.
 
The only other thing I could suggest is making a property on your page which
sets the text on the Label and then aoontate thge property w/ your custom
attribute.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Thanks for the response. I have looked into the Asp 2 localization
model and it doesn't quite do what I want it to.

It seems like a bit of a problem that it is impossible to add an
attribute to a control added declaratively in design view. I can't
believe there's no way to do it. I do want to do things the 2005 way
in every other regard because it's easier and better.

Brock Allen said:
If you need to add a custom attribute to the field, then don't use
partial classes and the new CodeFile directive. I think you're going
to have a struggle though, as the new VS.NET model doesn't want to do
things the old way :)

BTW, since your attribute is called [Localize] I'm wondering if the
new localization model in 2.0 will suit your needs:

http://beta.asp.net/QUICKSTART/aspnet/doc/localization/default.aspx

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

I had an aspx pag in .Net 1.1 with a label on it. As such I had a
code behind page with a declaration for that label.

When I convert to Asp.Net 2.0 the code behind is converted to a
partial class and the declaration for the label is removed. This is
what I expected to happen and I understand why it has happened.

The problem I have is that I had added a custom attribute to my
label declaration which I use to handle localization. e.g.

[Localize]
protected System.Web.UI.WebControls.Label lScreenTitle;
Since that declaration has been removed, so has the custom
attribute.
My question is, how do you add a custom attribute to a control on an
aspx page in Asp.Net 2.0 given that you no longer have access to the
control's declaration in the code-behind file?

Thanks,

Julian Jelfs.
 
Yes that's an idea I could try. It all starts to get a bit laborious then.

Brock Allen said:
The only other thing I could suggest is making a property on your page which
sets the text on the Label and then aoontate thge property w/ your custom
attribute.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Thanks for the response. I have looked into the Asp 2 localization
model and it doesn't quite do what I want it to.

It seems like a bit of a problem that it is impossible to add an
attribute to a control added declaratively in design view. I can't
believe there's no way to do it. I do want to do things the 2005 way
in every other regard because it's easier and better.

Brock Allen said:
If you need to add a custom attribute to the field, then don't use
partial classes and the new CodeFile directive. I think you're going
to have a struggle though, as the new VS.NET model doesn't want to do
things the old way :)

BTW, since your attribute is called [Localize] I'm wondering if the
new localization model in 2.0 will suit your needs:

http://beta.asp.net/QUICKSTART/aspnet/doc/localization/default.aspx

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

I had an aspx pag in .Net 1.1 with a label on it. As such I had a
code behind page with a declaration for that label.

When I convert to Asp.Net 2.0 the code behind is converted to a
partial class and the declaration for the label is removed. This is
what I expected to happen and I understand why it has happened.

The problem I have is that I had added a custom attribute to my
label declaration which I use to handle localization. e.g.

[Localize]
protected System.Web.UI.WebControls.Label lScreenTitle;
Since that declaration has been removed, so has the custom
attribute.
My question is, how do you add a custom attribute to a control on an
aspx page in Asp.Net 2.0 given that you no longer have access to the
control's declaration in the code-behind file?

Thanks,

Julian Jelfs.
 
Agreed.

Let me ask why the built-in localization scheme doesn't work for you? If
you need more control over it you can build your own expression builder such
that you get to define your own <%$ %> syntax in the pages. That would then
invoke your code to do your own conditional localization.....

-Brock
DevelopMentor
http://staff.develop.com/ballen


Yes that's an idea I could try. It all starts to get a bit laborious
then.

Brock Allen said:
The only other thing I could suggest is making a property on your
page which sets the text on the Label and then aoontate thge property
w/ your custom attribute.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Thanks for the response. I have looked into the Asp 2 localization
model and it doesn't quite do what I want it to.

It seems like a bit of a problem that it is impossible to add an
attribute to a control added declaratively in design view. I can't
believe there's no way to do it. I do want to do things the 2005 way
in every other regard because it's easier and better.

:

If you need to add a custom attribute to the field, then don't use
partial classes and the new CodeFile directive. I think you're
going to have a struggle though, as the new VS.NET model doesn't
want to do things the old way :)

BTW, since your attribute is called [Localize] I'm wondering if the
new localization model in 2.0 will suit your needs:

http://beta.asp.net/QUICKSTART/aspnet/doc/localization/default.aspx

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

I had an aspx pag in .Net 1.1 with a label on it. As such I had a
code behind page with a declaration for that label.

When I convert to Asp.Net 2.0 the code behind is converted to a
partial class and the declaration for the label is removed. This
is what I expected to happen and I understand why it has happened.

The problem I have is that I had added a custom attribute to my
label declaration which I use to handle localization. e.g.

[Localize]
protected System.Web.UI.WebControls.Label lScreenTitle;
Since that declaration has been removed, so has the custom
attribute.
My question is, how do you add a custom attribute to a control on
an
aspx page in Asp.Net 2.0 given that you no longer have access to
the
control's declaration in the code-behind file?
Thanks,

Julian Jelfs.
 
Well, the problem is that I don't really want it to be tied to culture. So
it's not really localization in that sense, it's rather the ability to
provide alternative sets of terminology (which might include a separate
langyage altogether) So I might have two different sets of terminology being
used within the same culture setting. That's really why I thought that the
language localization infrastructure provided by the .Net framework didn't
quite fit.

I also need to store my resources in a database rather than resource files,
but I think .Net 2 allows that right?

Brock Allen said:
Agreed.

Let me ask why the built-in localization scheme doesn't work for you? If
you need more control over it you can build your own expression builder such
that you get to define your own <%$ %> syntax in the pages. That would then
invoke your code to do your own conditional localization.....

-Brock
DevelopMentor
http://staff.develop.com/ballen


Yes that's an idea I could try. It all starts to get a bit laborious
then.

Brock Allen said:
The only other thing I could suggest is making a property on your
page which sets the text on the Label and then aoontate thge property
w/ your custom attribute.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Thanks for the response. I have looked into the Asp 2 localization
model and it doesn't quite do what I want it to.

It seems like a bit of a problem that it is impossible to add an
attribute to a control added declaratively in design view. I can't
believe there's no way to do it. I do want to do things the 2005 way
in every other regard because it's easier and better.

:

If you need to add a custom attribute to the field, then don't use
partial classes and the new CodeFile directive. I think you're
going to have a struggle though, as the new VS.NET model doesn't
want to do things the old way :)

BTW, since your attribute is called [Localize] I'm wondering if the
new localization model in 2.0 will suit your needs:

http://beta.asp.net/QUICKSTART/aspnet/doc/localization/default.aspx

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

I had an aspx pag in .Net 1.1 with a label on it. As such I had a
code behind page with a declaration for that label.

When I convert to Asp.Net 2.0 the code behind is converted to a
partial class and the declaration for the label is removed. This
is what I expected to happen and I understand why it has happened.

The problem I have is that I had added a custom attribute to my
label declaration which I use to handle localization. e.g.

[Localize]
protected System.Web.UI.WebControls.Label lScreenTitle;
Since that declaration has been removed, so has the custom
attribute.
My question is, how do you add a custom attribute to a control on
an
aspx page in Asp.Net 2.0 given that you no longer have access to
the
control's declaration in the code-behind file?
Thanks,

Julian Jelfs.
 

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

Back
Top