473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Forcing constructor from aspx

Is there any way in ASP.Net (1.1) to force a parameterized constructor
of an object from the server tag in the ASPX code? Alternatively, if
there any way to force the IDE to render tag properties in a specific
order?

For instance, let's say I have the following code for a custom server
control:

namespace Myspace
{
public class MyObject : WebControl
{
public MyObject(SubObjectType Type): base(HtmlTextWriterTag.Div)
{
_Type = Type;
}

public MyObject(): base(HtmlTextWriterTag.Div)
{
_Type = SubObjectType.Foo;
}

private SubObjectType _Type;

public string BuriedText
{
set
{
EnsureChildControls();
Control Sub = (Control) Controls[0];
Sub.Text = value;
}
}

override protected void CreateChildControls()
{

switch(_Type)
{
case SubObjectType.Foo:
{
FooControl Ctrl = new Myspace.FooControl();
Controls.Add(Ctrl)
}
case SubObjectType.Bar:
{
BarControl Ctrl = new Myspace.BarControl();
Controls.Add(Ctrl)
}
default:
break;
}
}
}
}

I want to pass "Bar" as the SubObjectType using a server tag in the
ASPX code. If I put the "type=" parameter BEFORE the "buriedtext="
parameter as in:

<myspace:myobject id="myobject1" type="bar" buriedtext="hello" />

the Type property is set before the BuriedText property. So when
CreateChildControls is executed, the correct subcontrol is created.
However, if I swap the order, as in:

<myspace:myobject id="myobject1" buriedtext="hello" type="bar" />

CreateChildControls is executed before the Type is set and I'm hosed.

I can work around this by editing all the server tags, but Visual
Studio likes to rearrange them again on me any time I edit a property.
What I'd really like is to do something like:

<myspace:myobject(bar) id="myobject1" buriedtext="hello" />

Any ideas?
Thanks.

--Tad

Mar 1 '06 #1
2 1247
Could an administrator (or MVP if you are able) please remove this thread? I
mistakenly submitted it with my email address and I'd like to minimize the
spam I receive as a result.

Thanks
--Tad
Mar 2 '06 #2
TadRichard <Ta********@discussions.microsoft.com> wrote:
Could an administrator (or MVP if you are able) please remove this thread? I
mistakenly submitted it with my email address and I'd like to minimize the
spam I receive as a result.


I'm afraid even if it could be done at this stage - and MVPs don't have
access - the way things work these days, your post will be on various
mirroring websites etc by now.

(Personally I find it better just to use my real email address
everywhere and just deal with spam. YMMV.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Pete Davis | last post by:
I know I can use reflection to call internal, protected, and private methods in a class, but I need to instantiate an object that is public but has an internal constructor (The CurrencyManager...
2
by: Paul Wu | last post by:
From what I understand, in ASP.NET, each HTTP requests is serviced by a separate thread. So if my code uses a static Class with shared members and properties, I can manage concurrent access by using...
40
by: Neo The One | last post by:
I think C# is forcing us to write more code by enforcing a rule that can be summarized as 'A local variable must be assgined *explicitly* before reading its value.' If you are interested in what...
8
by: Sam Kuehn | last post by:
How do I accomplish the fallowing (is it even possible). Say I write a UserControl "MyControl.ascx". Now I use LoadControl("MyControl.ascx"). But I really want MyControl to require parameters in...
4
by: TJS | last post by:
How can I override the default values, of a class constructor , from an ASP.net page ? Public Sub New( ) HeaderStyle.BackColor = ColorTranslator.FromHtml("#5C85AD") HeaderStyle.ForeColor =...
18
by: Zytan | last post by:
I just got a TypeInitializationException exception. Why it is a common cause for this? The InnerException is System.FormatException, although I don't see anything requesting something to be...
74
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
3
by: Ken Fine | last post by:
I am using ASP.NET's CreateUserWizard control. I want to force the visitor to use a username and e-mail address that I am providing in programming, and I do not want the visitor to be able to edit...
5
by: David Thielen | last post by:
Hi; We keep having to restart IIS after ASP.NET kills it. Below is what we have in the event log. Any idea what the problem is? thanks - dave Event code: 3003 Event message: A validation...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.