473,581 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(SubObj ectType Type): base(HtmlTextWr iterTag.Div)
{
_Type = Type;
}

public MyObject(): base(HtmlTextWr iterTag.Div)
{
_Type = SubObjectType.F oo;
}

private SubObjectType _Type;

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

override protected void CreateChildCont rols()
{

switch(_Type)
{
case SubObjectType.F oo:
{
FooControl Ctrl = new Myspace.FooCont rol();
Controls.Add(Ct rl)
}
case SubObjectType.B ar:
{
BarControl Ctrl = new Myspace.BarCont rol();
Controls.Add(Ct rl)
}
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:myobje ct id="myobject1" type="bar" buriedtext="hel lo" />

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

<myspace:myobje ct id="myobject1" buriedtext="hel lo" type="bar" />

CreateChildCont rols 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:myobje ct(bar) id="myobject1" buriedtext="hel lo" />

Any ideas?
Thanks.

--Tad

Mar 1 '06 #1
2 1256
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********@dis cussions.micros oft.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.co m>
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
18115
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 class). Is there a way to do this with reflection? I'm so mad at MS about the CurrencyManager design it makes me want to scream. It's been causing...
2
3738
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 something like the Monitor or ReaderWriterLock class. It is rather difficult to simulate multiple threads in a debug environment so I am hoping...
40
3024
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 I mean, please look at this feedback my me: ...
8
5232
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 the constructor for example MyContorl oMyControl = new MyContorl(employeeid). However I need to load the control at runtime so the have to call it...
4
2894
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 = Color.White HeaderStyle.Font.Bold = True End Sub
18
7112
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 formatted. I'm trying to invoke the use of a class, to force its static c'tor to run, which will run its unit test. Is there a good way to force all...
74
15930
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 creation of this implicit default constructor, to force the creation of a struct via my constructor only? Zytan
3
2582
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 the forms input. I am aware that I can roll my own Create User form by using the membership API, but I am lazy and want to use most of the...
5
3229
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 error has occurred. Event time: 6/23/2008 9:07:24 AM
0
7876
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7910
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6563
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3832
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1144
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.