Why is "<MyControl ... />" different to "<MyControl ...> </MyControl>"

Hi

I have made a CompositeControl and had it working fine. The sequence of events was: Page -> Page_Load(), MyControl -> CreateChildControls(). This was fine because I had to set a certain property in my control during page load before CreateChildControls was called.

Anyway.... suddenly it all stopped working and it turned out that the sequence of events changed to MyControl -> CreateChildControls(), Page -> Page_Load(). This caused it to blow up because the property was not set. After a few hours of pulling my hair out and undoing all the recent changes I had made it turns out that the cause of the problem was that I had changed my tag in the aspx file from <MyControl abc="xyz" ... /> to <MyControl abc="xyz" ...>  </MyControl>.

So... why does this change cause the whole thing to work in a different way, and what can I do about it?

Thanks

Buck

0
buckbuchanan
6/26/2008 10:31:15 AM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

5 Replies
793 Views

Similar Articles

[PageSpeed] 29

Hi,

<MyControl ...>  </MyControl> dictates that there is the possibility for HTML content to be entered between the tags, this bumps the control to the Pre_Render event - from memory not sure on the Pre_Render event, but you get the idea.
 


I hope this helps, if it answers your question, don't forget to mark it as such for those who come afterwards.

Regards,

Gareth Chidgey
Managing Director
PushInternet Ltd
0
chidge
6/26/2008 10:35:26 AM

Thanks for the super fast reply!! What is the best thing to do with my control? I need to be able to set this property in page load. Is there some other method I can override instead of CreateChildControls?

Thanks

0
buckbuchanan
6/26/2008 10:43:58 AM

 Hi,

You need to tell the control to be created in the page load event. Done it before but Im literally in the middle of rebuilding my PC so cant grab the code and cant think off hand, something like

 Page_Load

control mycontrol = new control

mycontrol.load();

 

sorry if thats a bit rough! It really has been a while.
 


I hope this helps, if it answers your question, don't forget to mark it as such for those who come afterwards.

Regards,

Gareth Chidgey
Managing Director
PushInternet Ltd
0
chidge
6/26/2008 11:04:47 AM

 There are a few processes that come before createchildcontrols, and after it.

Best practice is to load data inside your control in Overrides OnLoad(), which comes before Page_Load()

It might be the way you rendered the control.  Render methods seem to product different results, such as extra span tags

 
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

RenderContents(writer)

End Sub 

 
 
0
jkirkerx
6/26/2008 11:10:21 PM

Thanks for the replies folks. I hadn't realised that was what was happening. I have moved the code into an overridden load method and seems to work fine.

Thanks for all the replies.

 

0
buckbuchanan
6/27/2008 12:31:48 AM
Reply:

Similar Artilces:

"<table></table>" and "<frameset><frame></frame></frameset>" in perl/tk
Dear my friends... Anybody would be so kind telling me what is similar in perl/tk to arrange the location of a form written in perl/tk? I want a nice look for my perl/tk application. Somewhat like this below: 1. Name : <place to type-in> 2. Address : <place to type-in> 3. Telephone : <place to type-in> I have made the main menu of my application with "Menubutton". And I want if the user click on the menu that what the user see is only the aimed application displayed on the determined area (under the main menu) but the menu has no change in po...

what's the different from "<page src="">" and "<page codeBehind="">"
what's the different from "<page src="">" and "<page codeBehind="">" Thank YOU how to make session' life longer? Thank You This very question was asked only 5 days ago. Searching the forums would have yielded the answer you require. However, see this thread. Steven BeyRecursion: see Recursion You can set a new value for the Session Timeout in your web.config file. Or, you can do it in a page through this property: Session.Timeout Note that if you choose the second method, the timeout will only be modified on this page,...

Difference between <%# Bind("") %> and <%# Eval("") %>
Occassionally, I will find myself using Bind and Eval interchangeable.  I am unclea or what is the exact difference.  Can someone shed some light?Thanks,X Friend, it is something like this Data-binding expressions are contained within <%# and %> delimiters and use the Eval and Bind functions. The Eval function is used to define one-way (read-only) binding. The Bind function is used for two-way (updatable) binding. In addition to calling Eval and Bind methods to perform data binding in a data-binding expression, you can call any publicly scoped code within the <%# and %...

"Florian Ragwitz" <rafl@debian.org>, "Zefram" <zefram@fysh.org>, "Father Chrysostomos" <sprout@cpan.org>,
--0015175884b6a300aa04a8916f03 Content-Type: text/plain; charset=UTF-8 Howdy all. Bit of a slow week, as I didn't have net access for a couple of days. It was awful, and doesn't leave me with that much to report; But on the other hand, it was an awesome week - Midterm passed, the pad stuff got merged, and all the bugs in that started popping out. Fun : ) I'll follow up on that in another mail, so back to last week. With the pad merge, getting our and the error messages with scalar filehandles working done was only a few lines, which makes several TODO tests to pass;...

superreview cancelled: [Bug 226958] Bug 197315, "other" files: Convert <window class="dialog"> to <dialog> : [Attachment 137491] (Cv2) <Wallet*.*> (+ <*pref*>)
Serge GAUTHERIE <gautheri@noos.fr> has cancelled Serge GAUTHERIE <gautheri@noos.fr>'s request for superreview: Bug 226958: Bug 197315, "other" files: Convert <window class="dialog"> to <dialog> http://bugzilla.mozilla.org/show_bug.cgi?id=226958 Attachment 137491: (Cv2) <Wallet*.*> (+ <*pref*>) http://bugzilla.mozilla.org/attachment.cgi?id=137491&action=edit ...

superreview requested: [Bug 226958] Bug 197315, "other" files: Convert <window class="dialog"> to <dialog> : [Attachment 137491] (Cv2) <Wallet*.*> (+ <*pref*>)
Serge GAUTHERIE <gautheri@noos.fr> has asked Ben Goodger (I don't read bugmail) <bugs@bengoodger.com> for superreview: Bug 226958: Bug 197315, "other" files: Convert <window class="dialog"> to <dialog> http://bugzilla.mozilla.org/show_bug.cgi?id=226958 Attachment 137491: (Cv2) <Wallet*.*> (+ <*pref*>) http://bugzilla.mozilla.org/attachment.cgi?id=137491&action=edit ...

What is this for? "<label style=""display:none;"" for=""" & cboFieldType.ClientID.ToString & """>Type</label>"
I'm digging through the code of DNN and I found many ocurrences of this type of code: lblFieldType.Text = "<label style=""display:none;"" for=""" & cboFieldType.ClientID.ToString & """>Type</label>" What is that code for? The label is never displayed and I could not figure out what DDN uses it for. thank you This is for ADA compliance. The guidelines require that form elements have an associated label. This helps the text readers out with identifying the different parts of the form. BruceDynamic...

Code Behind or "<script runat="server">...code...</script>"?
Hi, I've just started learning asp.net after a number of years with VB. A lot of the examples I've been researching have placed the VB code directly onto the .aspx web page with a "<script runat="server">...code...</script>" format rather than placing the code in a "code behind" .vb page. Is there any reason for this other than the fact that you can place all the relevant code onto one example? From a .Net Studio point of view, it's seems to be far easier to use Code Behind, as one can take advantage of the "Auto Complete" features th...

What if I remove <form id="form1" runat="server"></form>
If I am creating an aspx page, which does not need to be a form, i.e. no input is taken from the user, do I need to encapsulate the whole page with in  <form1 runat="server">   What are the implications of removing the form? I realize there will be no viewstate, and again, I won't be able to accept user input, but will everything else work as expected? It seems to be so far, I've just not seen ANY examples where the form tag has been removed. Thanks, Darragh You need the server-side form tag if you are going to have server-side controls on the form.RyanRyan Olshan...

superreview requested: [Bug 427928] "ASSERTION: Non-border-colors case with borderColorStyleCount < 1 or > 3" and "ASSERTION: Unhandled border style" with <table style="outline: auto; "></table> : [At
Mats Palmgren <mats.palmgren@bredband.net> has asked David Baron [:dbaron] <dbaron@mozilla.com> for superreview: Bug 427928: "ASSERTION: Non-border-colors case with borderColorStyleCount < 1 or > 3" and "ASSERTION: Unhandled border style" with <table style="outline: auto;"></table> https://bugzilla.mozilla.org/show_bug.cgi?id=427928 Attachment 314802: Patch rev. 1 https://bugzilla.mozilla.org/attachment.cgi?id=314802&action=edit ------- Additional Comments from Mats Palmgren <mats.palmgren@bredband.net> Not sure...

"<->" as "->" with automatic "is rw"
I like that arguments will be readonly by default. But when I look at my current code, I see that I would be typing " is rw" quite a lot, which in my opinion is too long for a thing that occurs very often. Every such situation in my code is a foreach loop. A thing that in Perl 6 will mostly be used with the pointy sub declaration syntax. If I'm not mistaken, <-> is still available. It communicates "bidirectional" and that is more or less the same as read/write access. I'm proposing for zip(@foos, @bars, @xyzzies) <-> $foo, $bar, $xyzz...

superreview denied: [Bug 427928] "ASSERTION: Non-border-colors case with borderColorStyleCount < 1 or > 3" and "ASSERTION: Unhandled border style" with <table style="outline: auto; "></table> : [Attac
David Baron [:dbaron] <dbaron@mozilla.com> has denied Mats Palmgren <mats.palmgren@bredband.net>'s request for superreview: Bug 427928: "ASSERTION: Non-border-colors case with borderColorStyleCount < 1 or > 3" and "ASSERTION: Unhandled border style" with <table style="outline: auto;"></table> https://bugzilla.mozilla.org/show_bug.cgi?id=427928 Attachment 314802: Patch rev. 1 https://bugzilla.mozilla.org/attachment.cgi?id=314802&action=edit ...

<ypbp:CategoryTree id="categoryTree" runat="server"></ypbp:CategoryTree>
Hi All, I hope you can help a very confused beginner. I am writing a site that has a navigation tree configured from a database. I wanted to create a reusable piece of code that "draws" the navigation tree based on a request parameter that indicates to the code how to draw the tree. For example, the first time the page loads it will draw all the top level menu items only, and when a user clicks on one of those options it would draw all the top items and also the children of the item just clicked on etc... I want this to be reusable because I am writing an admin backend to the website as we...

can I delete <form id="form1" runat="server"> and </form>
Hi: Our website is written by using simple html code, one of the page has some virtual shopping cart code with <form> ....</form>, (for example here: http://www.centercoin.com/coin_supplies/coin_collecting_starter_set.htm ), if I have 10 products, I will have 10 of <from> ...</form> in this page, that is ok. Now, I am trying to redesign the website using asp.net2.0, I notice all the asp page will automatically create a <form id="form1" runat="server"> ...</form>, such as: <html xmlns="http://www.w3.org/19...

Web resources about - Why is "<MyControl ... />" different to "<MyControl ...> </MyControl>" - asp.net.custom-server-controls

Resources last updated: 1/19/2016 9:05:59 PM