Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

literal object definitions in asp.net

Status
Not open for further replies.

mirirom

Programmer
Jul 21, 2001
110
US
hi, i'm wondering if someone can explain where object instances are actually defined in the page creation lifecycle of asp.net pages.

for instance (no pun intended), you create a webform, add a few server controls, set some props, compile, etc. and voila! the page is displayed.

however, when you view the underlying class for your page, you can see the declarations for your server controls but not their definitions. where are these guys actually instantiated? is there some behind the scenes magic in the call to base.onInit()?

the reason i'm interested is because i'm trying to come up with an inheritance scheme for similar webpages. it'd be nice if, say for example, you created page foo.aspx that contained a common set of server controls applicable to all derived types of foos. perhaps i'm trying to replicate the behaviour of "visual inheritance" found in .NET win32 apps.

thanks for the input!

..:: mirirom ::..
 
Right - I believe the answer is somewhere within the System.Web.UI.Control class (which Page inherits). It might be the OnInit, but I think it is actually in an abstract method called Render(), which finds all the child controls, instantiates them, and tells them to produce their HTML output into the current Html text stream.

If you find out any more, I'd be interested in knowing too.



David
[pipe]
 
David,

this wasn't an easy topic to uncover but i got some decent feedback on one of the MS dotnet newsgroups. pretty much all text out there on page and server control lifecycles outline the various stages of how the pages are "rendered". fine. but they only *elude* to the fact that when you compile your code, an underlying public class called yourPageName_aspx is created. in fact, it inherits from two sources: the codebehind class (which inherits from page) and interface System.Web.SessionState.IRequiresSessionState

each *declared* control in your codebehind class is built by methods added in this new public class. for instance, textbox txtFoo is declared as protected in the codebehind class. when you compile, the new public class for the page creates a method called
Code:
private System.Web.UI.Control __BuildControltxtFoo(){
  System.Web.UI.WebControls.Textbox __ctrl;
  __ctrl = new System.Web.UI.WebControls.TextBox();
  this.txtFoo = __ctrl;
  __ctrl.ID = "txtFoo";
  return __ctrl;
}

the architecture gets even more interesting (i need a life). this public class also declares a protected member of type yourCodeBehindClass, and creates a similiar BuildControl fuction for it. this fuction contains all the other control building fuctions and is called from an overridden protected function FrameworkInitialize(). i'm not sure where this guy is called from but i'm guessing it's somewhere around the time initial or postback client calls are made.

perhaps someone could come up with a better explanation (i'm still spelunkering around the framework's core processing mechanisms). basically i was given a toy example to compile, then to disect the error code. be sure that client-side debugging is set up correctly. the error seen in the browser provides a link to see the COMPLETE compiled ojbect code of your page - fascinating.

here's the broken toy...
Code:
<%@ Page language=&quot;c#&quot; codebehind=&quot;foo.cs&quot; inherits=&quot;foo&quot;%>
<html>
    <body>
        <form runat=server>
            <asp:button runat=server Text=&quot;Button&quot;
OnClick=&quot;NotExistsMethod&quot;></asp:button>
        </form>
    </body>
</html>


..:: mirirom ::..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top