Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Need help on landling templates in a WebControl.


Message #1 by "Thomas Tomiczek" <thona@g...> on Fri, 6 Oct 2000 11:36:39 +0200
This is a multi-part message in MIME format.



------_=_NextPart_001_01C02F78.EDB799AC

Content-Type: text/plain;

	charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



> Hello,

>

> I have a very simpla WebControl (actually written by Scott Guthrie [

> :-) ] that I need to extend.

>

> Its code is:

> -->

>     public class Fragment : Control {

>

>         private ITemplate content = null;

>    

>         public ITemplate Content {

>            

>             get {

>                 return content;

>             }

>             set {

>                 content = value;

>             }

>         }

>     }

> <--

>

> Now, my problem is that when I use this control such as in

> -->

> 	<DkWeb:Fragment id=3D"ContentLeftTop">

> 		<template name=3D"Content">

> 			<asp:TextBox id=3D"ctlSurname" runat=3D"server"

> Colums=3D"20"  MaxLength=3D"20" TextMode=3D"SingleLine" 

width=3D"100%"/>

> 		</template>

> 	</DkWeb:Fragment>

> <--

> I can not access the Textbox by its Id. Normally there is - on the

> page - a variable generated whose name is the ID. In this case, the

> Name is somehow composed by the name of the page plus another verb

> plus a number - which is making it impossible to access the control,

> because the number can change when the template is edited.

>

> On the bad side: all the relevant parts of the documentation seem

> "still to come".

>

> Now, anyone has any knowledge on how I can take handle this? What I

> actually want is that the above textbox is accessible from Script by

> its id as would normally be the case.

>

> Scott, if you read this - this is a similar request to the email I

> sent to you yesterday, just that the email was longer and contained

> the complete generated source for a page.

>

> Any help is greatly appreciated.

>

> Thomas Tomiczek




Message #2 by Rob Howard <rhoward@m...> on Fri, 6 Oct 2000 07:35:51 -0700
This message is in MIME format. Since your mail reader does not understand

this format, some or all of this message may not be legible.



------_=_NextPart_001_01C02FA2.B9C979A6

Content-Type: text/plain;

	charset="iso-8859-1"



Hi Thomas,

 

I believe you need to add some more code to the control to render the

textbox within DkWeb:Fragment using templates. I didn't have time to write

an example, but take a look at the ASP+ quickstarts "Authoring Custom

Contorls" section (towards the bottom of the page).

 

The TextBox control is created as child control of the parent. Without

templates (when it's only a simple composite control), you can access the

TextBox control as follows:

 

 void Page_Load(){

   TextBox ctlSurname = (TextBox) ContentLeftTop.FindControl("ctlSurname");

   ctlSurname.Text = "Hello from ctlSurname";

 }



another problem, you need to mark DkWeb:Framgment with a runat=server

property:

 

        <DkWeb:Fragment id="ContentLeftTop" runat=server>  



Hope that helps.

 

Thanks,

Rob







office  xxx.xxx.xxxx  | cell  xxx.xxx.xxxx  | fax  xxx.xxx.xxxx  (attn: rhoward) 



-----Original Message-----

From: Thomas Tomiczek [mailto:thona@g...]

Sent: Friday, October 06, 2000 2:37 AM

To: ASP+

Subject: [aspx] Need help on landling templates in a WebControl.







Hello, 



I have a very simpla WebControl (actually written by Scott Guthrie [ :-) ]

that I need to extend. 



Its code is: 

--> 

    public class Fragment : Control { 



        private ITemplate content = null; 

    

        public ITemplate Content { 

            

            get { 

                return content; 

            } 

            set { 

                content = value; 

            } 

        } 

    } 

<-- 



Now, my problem is that when I use this control such as in 

--> 

        <DkWeb:Fragment id="ContentLeftTop"> 

                <template name="Content"> 

                        <asp:TextBox id="ctlSurname" runat="server"

Colums="20"  MaxLength="20" TextMode="SingleLine" width="100%"/>



                </template> 

        </DkWeb:Fragment> 

<-- 

I can not access the Textbox by its Id. Normally there is - on the page - a

variable generated whose name is the ID. In this case, the Name is somehow

composed by the name of the page plus another verb plus a number - which is

making it impossible to access the control, because the number can change

when the template is edited.



On the bad side: all the relevant parts of the documentation seem "still to

come". 



Now, anyone has any knowledge on how I can take handle this? What I actually

want is that the above textbox is accessible from Script by its id as would

normally be the case.



Scott, if you read this - this is a similar request to the email I sent to

you yesterday, just that the email was longer and contained the complete

generated source for a page.



Any help is greatly appreciated. 



Thomas Tomiczek 



--- 






Message #3 by "Thomas Tomiczek" <thona@g...> on Fri, 6 Oct 2000 17:25:17 +0200
This is a multi-part message in MIME format.



------_=_NextPart_001_01C02FA9.A1F0173E

Content-Type: text/plain;

	charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



Hello Rob,



well, its actually a little bit more complicated because this code was

written by Scott Guthrie :-).





The Fragment is included in something called a FragmentHolder that

actually looks like this:

-->

using System;

using System.Collections;

using System.Web;

using System.Web.UI;



namespace Daikiri.Web {



    [ ControlBuilderAttribute(typeof(FragmentBuilder)) ]

    public class FragmentHolder : Control, INamingContainer {



        private String basedOn =3D null;

   

        public String BasedOn {



            get {

                return basedOn;

            }

            set {

                basedOn =3D value;

            }

        }



        public ITemplate LoadFragmentTemplate(System.Web.UI.Page page,

String fragmentName) {

           

            // Attempt to locate requested fragment from children

collection



            // BugBug: The below walk code is inefficient. Instead, we

should

            // just use Control.FindControl to locate the appropriate

control.

            // This does a hashtable lookup on the current naming

container.

            // However, in the PDC bits there was a bug which prevented

            // Control.FindControl from working if the controls in

quetion

            // were unsited. Need to modify below code in Beta1.



            foreach (Control child in this.Controls) {



                if ((child.ID =3D=3D fragmentName) && (child is 

Fragment)) {



                    return ((Fragment) child).Content;

                }

            }



            // If the fragment is not in the children collection,

attempt to

            // resolve it from a parent page to see if it is inherited



            if (this.BasedOn !=3D null) {



                Control basepage =3D page.LoadControl(basedOn);



                if (basepage =3D=3D null) {

                    throw new Exception("Couldn't load base page: " +

basedOn);

                }



                foreach (Control child in basepage.Controls) {



                    if (child is FragmentHolder) {

                        return ((FragmentHolder)

child).LoadFragmentTemplate(page, fragmentName);

                    }

                }

            }



            throw new Exception("Cannot find " + fragmentName + "

fragment!");

        }



        protected override void CreateChildControls() {

           

            // Load "main" fragment of page -- this is the entrypoint

            // for the page and controls overall page rendering



            ITemplate maintemplate =3D LoadFragmentTemplate(Page, 

"main");





            // Instantiate "main" fragment and insert it into the page

tree



            maintemplate.Initialize(this);

        }

    }







    // The below custom ControlBuilder implementation enables page

developers to

    // drop <dell:fragment> sections within a <dell:fragmentholder>

section

    // without having to have "runat=3Dserver" attributes on them.



    public class FragmentBuilder : ControlBuilder {



        public override Type GetChildControlType(string tagName,

IDictionary attribs) {



            if (tagName.ToLower().EndsWith("fragment")) {

                return typeof(Fragment);

            }



            return null;

        }

    }

}



<--



If you look at the FragmentBuilder - it takes care that there is no need

for runat=3D"server".



The problem is that the names the controls get in the generated code are

somehow funny. something like PAGENAME_Ctrl22. Might bee (its all

undocumented) that I need to extend the FragmentBuilder, but how?



Thomas Tomiczek







-----Original Message-----

From: Rob Howard [mailto:rhoward@m...]

Sent: Freitag, 6. Oktober 2000 16:36

To: ASP+

Subject: [aspx] RE: Need help on landling templates in a WebControl.





Hi Thomas,



I believe you need to add some more code to the control to render the

textbox within DkWeb:Fragment using templates. I didn't have time to

write an example, but take a look at the ASP+ quickstarts "Authoring

Custom Contorls" section (towards the bottom of the page).



The TextBox control is created as child control of the parent. Without

templates (when it's only a simple composite control), you can access

the TextBox control as follows:



 void Page_Load(){

   TextBox ctlSurname =3D (TextBox)

ContentLeftTop.FindControl("ctlSurname");

   ctlSurname.Text =3D "Hello from ctlSurname";

 }



another problem, you need to mark DkWeb:Framgment with a runat=3Dserver

property:



        <DkWeb:Fragment id=3D"ContentLeftTop" runat=3Dserver> 



Hope that helps.



Thanks,

Rob







office  xxx.xxx.xxxx  | cell  xxx.xxx.xxxx  | fax  xxx.xxx.xxxx  (attn:

rhoward)



-----Original Message-----

From: Thomas Tomiczek [mailto:thona@g...]

Sent: Friday, October 06, 2000 2:37 AM

To: ASP+

Subject: [aspx] Need help on landling templates in a WebControl.







Hello,



I have a very simpla WebControl (actually written by Scott Guthrie [ :-)

] that I need to extend.



Its code is:

-->

    public class Fragment : Control {



        private ITemplate content =3D null;

   

        public ITemplate Content {

           

            get {

                return content;

            }

            set {

                content =3D value;

            }

        }

    }

<--



Now, my problem is that when I use this control such as in

-->

        <DkWeb:Fragment id=3D"ContentLeftTop">

                <template name=3D"Content">

                        <asp:TextBox id=3D"ctlSurname" runat=3D"server"

Colums=3D"20"  MaxLength=3D"20" TextMode=3D"SingleLine" width=3D"100%"/>



                </template>

        </DkWeb:Fragment>

<--

I can not access the Textbox by its Id. Normally there is - on the page

- a variable generated whose name is the ID. In this case, the Name is

somehow composed by the name of the page plus another verb plus a number

- which is making it impossible to access the control, because the

number can change when the template is edited.



On the bad side: all the relevant parts of the documentation seem "still

to come".



Now, anyone has any knowledge on how I can take handle this? What I

actually want is that the above textbox is accessible from Script by its

id as would normally be the case.



Scott, if you read this - this is a similar request to the email I sent

to you yesterday, just that the email was longer and contained the

complete generated source for a page.



Any help is greatly appreciated.



Thomas Tomiczek



---



---






Message #4 by "Thomas Tomiczek" <thona@g...> on Fri, 6 Oct 2000 17:39:02 +0200
This is a multi-part message in MIME format.



------_=_NextPart_001_01C02FAB.8D717EF4

Content-Type: text/plain;

	charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



Hello,



I had a second look at the quickstart and actually what I try to do is

similar to Custom Parsing Controls second Example. But I need the

contained template to be "first class code", i.e. I need to be able to

access the controls defined in there as scribt. An example page is:

-->

<%@ Page Language=3D"C#"%>

<%@ Assembly src=3D"Daikiri.Membership.cs" %>

<%@ Register TagPrefix=3D"DkWeb" Namespace=3D"Daikiri.Web" %>

<%@ Import Namespace=3D"System.Data" %>

<%@ Import Namespace=3D"System.Data.SQL" %>

<%@ Import Namespace=3D"Daikiri.Membership" %>

<script runat=3D"server">



 protected void Page_Load(Object Src, EventArgs e)

 {



dsnDaikiri=3D(String)((Hashtable)Context.GetConfig("daikiri"))["database"

]

;



dsnDictionary=3D(String)((Hashtable)Context.GetConfig("daikiri"))["dictio

n

ary"];



  SQLDataReader reader =3D null;



  // If this is an original posting, we need to handle some setup here

  if (!IsPostBack) {



   MemberManager mgr =3D new MemberManager (dsnDaikiri);



   DataView dv;

   dv =3D mgr.ListDomains ();

   foreach (DataRowView  r in dv) {

    ListItem newItem =3D new ListItem ( r["Name"].ToString());

    //ctlUserDomain.Items.Add (newItem);

   }



   /*

  }

 }





    protected void atnSave (Object sender, EventArgs e) {

  // This routine actually only does something if the validations did OK

  if (IsValid) {

  }

 }



 // this is the connection string used to set up the MemberManager

 String dsnDaikiri;

 String dsnDictionary;



</script>

<DkWeb:FragmentHolder BasedOn=3D"/template175a550.aspx" runat=3Dserver>



 <DkWeb:Fragment id=3D"ContentRight">

  <template name=3D"Content">

   <table width=3D"100%" border=3D"1">

    <tr><td width=3D"50%">Name (4-30 Zeichen):</td>

     <td>

      <table width=3D"100%" cellspacing=3D"0" cellpadding=3D"0"><tr><td

widht=3D"50%">

       <asp:TextBox id=3D"ctlUserName" runat=3D"server" Colums=3D"20"

MaxLength=3D"20" TextMode=3D"SingleLine" width=3D"100%"/>

      </td><td width=3D"50%">

       <asp:DropDownList id=3D"ctlUserDomain" runat=3D"server"

width=3D"100%"/>

      </td></tr></table>

     </td></tr>

    <tr><td width=3D"50%">Passwort (4-30 Zeichen):</td>

     <td><asp:TextBox id=3D"ctlPassword1" runat=3D"server" Colums=3D"30"

MaxLength=3D"30" TextMode=3D"SingleLine" width=3D"100%"/></td></tr>

    <tr><td width=3D"50%">Passwort (Wiederholung):</td>

     <td><asp:TextBox id=3D"ctlPassword2" runat=3D"server" Colums=3D"20"

MaxLength=3D"20" TextMode=3D"SingleLine" width=3D"100%"/></td></tr>

    <tr><td colspan=3D"2">Bitte geben Sie ihr Passwort beide Male gleich

geschrieben ein.</td></tr>



    <tr><td colspan=3D"2"> </td></tr>



    <tr><td width=3D"50%">Geschlecht:</td>

     <td><asp:DropDownList id=3D"ctlSex" runat=3D"server"

width=3D"100%"/></td></tr>

    <tr><td width=3D"50%">Titel:</td>

     <td><asp:TextBox id=3D"ctlTitle" runat=3D"server" Colums=3D"20"

MaxLength=3D"20" TextMode=3D"SingleLine" width=3D"100%"/></td></tr>

    <tr><td width=3D"50%">Vorname:</td>

     <td><asp:TextBox id=3D"ctlName" runat=3D"server" Colums=3D"20"

MaxLength=3D"20" TextMode=3D"SingleLine" width=3D"100%"/></td></tr>

    <tr><td width=3D"50%">Nachname:</td>

     <td><asp:TextBox id=3D"ctlSurname" runat=3D"server" Colums=3D"20"

MaxLength=3D"20" TextMode=3D"SingleLine" width=3D"100%"/></td></tr>



    <tr><td colspan=3D"2"> </td></tr>



    <tr><td width=3D"50%">Geburtstag:</td>

     <td><asp:TextBox id=3D"ctlBirthdate" runat=3D"server" Colums=3D"20"

MaxLength=3D"20" TextMode=3D"SingleLine" width=3D"100%"/></td></tr>

    <tr><td width=3D"50%">Land:</td>

     <td><asp:DropDownList id=3D"ctlCountry" runat=3D"server"

width=3D"100%"/></td></tr>



    <tr><td colspan=3D"2"> </td></tr>

    <tr><td colspan=3D"2" align=3D"center">

     <asp:Button runat=3D"server" Text=3D"Speichern" 

OnClick=3D"atnSave"/>

     </td></tr>

   </table>

  </template>

 </DkWeb:Fragment>



</DkWeb:fragmentholder>

<--

This Fragment-Stuff has been done for visual inheritance - I actually

exchange a part of athe page inherited from another page, in this case

from "/template175a550.aspx.



Now, in the template I define a number of controls, like for example

<asp:DropDownList id=3D"ctlUserDomain" runat=3D"server" 

width=3D"100%"/>.



From m yscript. I want this cotnrol to be available as ctluserDomain,

but it is not - it gets aavailable using a "funny name" as mentioned in

my earlier post.



So actually I think the ControlBuilder is somehow "f*****g this up" -

sorry for the words. The problem is there is NO documentation on how

this really works and how stuff interoperates, just the Quickstart

(which are not THAT helpfull on this level) and a lot of "still to

come".



Now its your turn again.



The result, btw, will be available for free download, this has been

discussed with Scott.



Thomas Tomiczek



-----Original Message-----

From: Rob Howard [mailto:rhoward@m...]

Sent: Freitag, 6. Oktober 2000 16:36

To: ASP+

Subject: [aspx] RE: Need help on landling templates in a WebControl.





Hi Thomas,



I believe you need to add some more code to the control to render the

textbox within DkWeb:Fragment using templates. I didn't have time to

write an example, but take a look at the ASP+ quickstarts "Authoring

Custom Contorls" section (towards the bottom of the page).



The TextBox control is created as child control of the parent. Without

templates (when it's only a simple composite control), you can access

the TextBox control as follows:



 void Page_Load(){

   TextBox ctlSurname =3D (TextBox)

ContentLeftTop.FindControl("ctlSurname");

   ctlSurname.Text =3D "Hello from ctlSurname";

 }



another problem, you need to mark DkWeb:Framgment with a runat=3Dserver

property:



        <DkWeb:Fragment id=3D"ContentLeftTop" runat=3Dserver> 



Hope that helps.



Thanks,

Rob







office  xxx.xxx.xxxx  | cell  xxx.xxx.xxxx  | fax  xxx.xxx.xxxx  (attn:

rhoward)



-----Original Message-----

From: Thomas Tomiczek [mailto:thona@g...]

Sent: Friday, October 06, 2000 2:37 AM

To: ASP+

Subject: [aspx] Need help on landling templates in a WebControl.







Hello,



I have a very simpla WebControl (actually written by Scott Guthrie [ :-)

] that I need to extend.



Its code is:

-->

    public class Fragment : Control {



        private ITemplate content =3D null;

   

        public ITemplate Content {

           

            get {

                return content;

            }

            set {

                content =3D value;

            }

        }

    }

<--



Now, my problem is that when I use this control such as in

-->

        <DkWeb:Fragment id=3D"ContentLeftTop">

                <template name=3D"Content">

                        <asp:TextBox id=3D"ctlSurname" runat=3D"server"

Colums=3D"20"  MaxLength=3D"20" TextMode=3D"SingleLine" width=3D"100%"/>



                </template>

        </DkWeb:Fragment>

<--

I can not access the Textbox by its Id. Normally there is - on the page

- a variable generated whose name is the ID. In this case, the Name is

somehow composed by the name of the page plus another verb plus a number

- which is making it impossible to access the control, because the

number can change when the template is edited.



On the bad side: all the relevant parts of the documentation seem "still

to come".



Now, anyone has any knowledge on how I can take handle this? What I

actually want is that the above textbox is accessible from Script by its

id as would normally be the case.



Scott, if you read this - this is a similar request to the email I sent

to you yesterday, just that the email was longer and contained the

complete generated source for a page.



Any help is greatly appreciated.



Thomas Tomiczek



---



---






Message #5 by Rob Howard <rhoward@m...> on Fri, 6 Oct 2000 10:11:07 -0700
This message is in MIME format. Since your mail reader does not understand

this format, some or all of this message may not be legible.



------_=_NextPart_001_01C02FB8.6ADDA01A

Content-Type: text/plain;

	charset="iso-8859-1"



Thomas,

 

Well, see what happens when you don't send all the code the first time :)

 

I'll take a look at it later today.. unless Scott beats me to it.

 

Thanks,

Rob

 





office  xxx.xxx.xxxx  | cell  xxx.xxx.xxxx  | fax  xxx.xxx.xxxx  (attn: rhoward) 



-----Original Message-----

From: Thomas Tomiczek [mailto:thona@g...]

Sent: Friday, October 06, 2000 8:25 AM

To: ASP+

Subject: [aspx] RE: Need help on landling templates in a WebControl.





Hello Rob,

 

well, its actually a little bit more complicated because this code was

written by Scott Guthrie :-).

 

 

The Fragment is included in something called a FragmentHolder that actually

looks like this:

-->

using System; 

using System.Collections; 

using System.Web; 

using System.Web.UI; 

 

namespace Daikiri.Web { 

 

    [ ControlBuilderAttribute(typeof(FragmentBuilder)) ] 

    public class FragmentHolder : Control, INamingContainer { 

 

        private String basedOn = null; 

    

        public String BasedOn { 

 

            get { 

                return basedOn; 

            } 

            set { 

                basedOn = value; 

            } 

        } 

 

        public ITemplate LoadFragmentTemplate(System.Web.UI.Page page,

String fragmentName) { 

            

            // Attempt to locate requested fragment from children collection



 

            // BugBug: The below walk code is inefficient. Instead, we

should 

            // just use Control.FindControl to locate the appropriate

control. 

            // This does a hashtable lookup on the current naming container.



            // However, in the PDC bits there was a bug which prevented 



            // Control.FindControl from working if the controls in quetion 

            // were unsited. Need to modify below code in Beta1. 

 

            foreach (Control child in this.Controls) { 

 

                if ((child.ID == fragmentName) && (child is Fragment)) { 

                    return ((Fragment) child).Content; 

                } 

            } 

 

            // If the fragment is not in the children collection, attempt to



            // resolve it from a parent page to see if it is inherited 

 

            if (this.BasedOn != null) { 

 

                Control basepage = page.LoadControl(basedOn); 

 

                if (basepage == null) { 

                    throw new Exception("Couldn't load base page: " +

basedOn); 

                } 

 

                foreach (Control child in basepage.Controls) { 

 

                    if (child is FragmentHolder) { 

                        return ((FragmentHolder)

child).LoadFragmentTemplate(page, fragmentName); 

                    } 

                } 

            } 

 

            throw new Exception("Cannot find " + fragmentName + "

fragment!"); 

        } 

 

        protected override void CreateChildControls() { 

            

            // Load "main" fragment of page -- this is the entrypoint 

            // for the page and controls overall page rendering 

 

            ITemplate maintemplate = LoadFragmentTemplate(Page, "main"); 

 

            // Instantiate "main" fragment and insert it into the page tree 

 

            maintemplate.Initialize(this); 

        } 

    } 

 

 

 

    // The below custom ControlBuilder implementation enables page

developers to 

    // drop <dell:fragment> sections within a <dell:fragmentholder> section 

    // without having to have "runat=server" attributes on them. 

 

    public class FragmentBuilder : ControlBuilder { 

 

        public override Type GetChildControlType(string tagName, IDictionary

attribs) { 

 

            if (tagName.ToLower().EndsWith("fragment")) { 

                return typeof(Fragment); 

            } 

 

            return null; 

        } 

    } 

} 



<--

 

If you look at the FragmentBuilder - it takes care that there is no need for

runat="server".

 

The problem is that the names the controls get in the generated code are

somehow funny. something like PAGENAME_Ctrl22. Might bee (its all

undocumented) that I need to extend the FragmentBuilder, but how?

 

Thomas Tomiczek

 

 



-----Original Message-----

From: Rob Howard [mailto:rhoward@m...]

Sent: Freitag, 6. Oktober 2000 16:36

To: ASP+

Subject: [aspx] RE: Need help on landling templates in a WebControl.





Hi Thomas,

 

I believe you need to add some more code to the control to render the

textbox within DkWeb:Fragment using templates. I didn't have time to write

an example, but take a look at the ASP+ quickstarts "Authoring Custom

Contorls" section (towards the bottom of the page).

 

The TextBox control is created as child control of the parent. Without

templates (when it's only a simple composite control), you can access the

TextBox control as follows:

 

 void Page_Load(){

   TextBox ctlSurname = (TextBox) ContentLeftTop.FindControl("ctlSurname");

   ctlSurname.Text = "Hello from ctlSurname";

 }



another problem, you need to mark DkWeb:Framgment with a runat=server

property:

 

        <DkWeb:Fragment id="ContentLeftTop" runat=server>  



Hope that helps.

 

Thanks,

Rob







office  xxx.xxx.xxxx  | cell  xxx.xxx.xxxx  | fax  xxx.xxx.xxxx  (attn: rhoward) 



-----Original Message-----

From: Thomas Tomiczek [mailto:thona@g...]

Sent: Friday, October 06, 2000 2:37 AM

To: ASP+

Subject: [aspx] Need help on landling templates in a WebControl.







Hello, 



I have a very simpla WebControl (actually written by Scott Guthrie [ :-) ]

that I need to extend. 



Its code is: 

--> 

    public class Fragment : Control { 



        private ITemplate content = null; 

    

        public ITemplate Content { 

            

            get { 

                return content; 

            } 

            set { 

                content = value; 

            } 

        } 

    } 

<-- 



Now, my problem is that when I use this control such as in 

--> 

        <DkWeb:Fragment id="ContentLeftTop"> 

                <template name="Content"> 

                        <asp:TextBox id="ctlSurname" runat="server"

Colums="20"  MaxLength="20" TextMode="SingleLine" width="100%"/>



                </template> 

        </DkWeb:Fragment> 

<-- 

I can not access the Textbox by its Id. Normally there is - on the page - a

variable generated whose name is the ID. In this case, the Name is somehow

composed by the name of the page plus another verb plus a number - which is

making it impossible to access the control, because the number can change

when the template is edited.



On the bad side: all the relevant parts of the documentation seem "still to

come". 



Now, anyone has any knowledge on how I can take handle this? What I actually

want is that the above textbox is accessible from Script by its id as would

normally be the case.



Scott, if you read this - this is a similar request to the email I sent to

you yesterday, just that the email was longer and contained the complete

generated source for a page.



Any help is greatly appreciated. 



Thomas Tomiczek 



--- 



--- 



--- 






Message #6 by "Thomas Tomiczek" <thona@g...> on Sat, 7 Oct 2000 07:59:04 +0200
This is a multi-part message in MIME format.



------_=_NextPart_001_01C03023.B26AFDDE

Content-Type: text/plain;

	charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



Yeah,



btw theres another class involved, which is



-->

using System;

using System.Collections;

using System.Web;

using System.Web.UI;



namespace Daikiri.Web {



    public class FragmentReference : Control, INamingContainer {



        private String reference =3D null;



        public String Ref {

           

            get {

                return reference;

            }

            set {

                reference =3D value;

            }

        }



        protected override void CreateChildControls() {

           

            // Walk parent hierarchy to locate parent

<dell:fragmentholder> control



            Control fragmentHolder =3D this.Parent;



            while ((fragmentHolder !=3D null) && ((fragmentHolder is

FragmentHolder)) !=3D true) {

                fragmentHolder =3D fragmentHolder.Parent;

            }



            // Obtain Fragment Template



            ITemplate template =3D ((FragmentHolder)

fragmentHolder).LoadFragmentTemplate(Page, reference);



            // Instantiate and insert fragment into tree



            template.Initialize(this);

        }

    }

}

<--



Hm, I could actually send you a complete sample project if you want.



Scott seems to be travelling around - no post from him the last days. So

you have a real good chance at beating him.



I really wished the Beta1 would be out - I assume with a little bit more

documentation I would be able to figure this out myself.



Thanks again



Thomas





-----Original Message-----

From: Rob Howard [mailto:rhoward@m...]

Sent: Freitag, 6. Oktober 2000 19:11

To: ASP+

Subject: [aspx] RE: Need help on landling templates in a WebControl.





Thomas,



Well, see what happens when you don't send all the code the first time

:)



I'll take a look at it later today.. unless Scott beats me to it.



Thanks,

Rob







office  xxx.xxx.xxxx  | cell  xxx.xxx.xxxx  | fax  xxx.xxx.xxxx  (attn:

rhoward)



-----Original Message-----

From: Thomas Tomiczek [mailto:thona@g...]

Sent: Friday, October 06, 2000 8:25 AM

To: ASP+

Subject: [aspx] RE: Need help on landling templates in a WebControl.





Hello Rob,



well, its actually a little bit more complicated because this code was

written by Scott Guthrie :-).





The Fragment is included in something called a FragmentHolder that

actually looks like this:

-->

using System;

using System.Collections;

using System.Web;

using System.Web.UI;



namespace Daikiri.Web {



    [ ControlBuilderAttribute(typeof(FragmentBuilder)) ]

    public class FragmentHolder : Control, INamingContainer {



        private String basedOn =3D null;

   

        public String BasedOn {



            get {

                return basedOn;

            }

            set {

                basedOn =3D value;

            }

        }



        public ITemplate LoadFragmentTemplate(System.Web.UI.Page page,

String fragmentName) {

           

            // Attempt to locate requested fragment from children

collection



            // BugBug: The below walk code is inefficient. Instead, we

should

            // just use Control.FindControl to locate the appropriate

control.

            // This does a hashtable lookup on the current naming

container.

            // However, in the PDC bits there was a bug which prevented

            // Control.FindControl from working if the controls in

quetion

            // were unsited. Need to modify below code in Beta1.



            foreach (Control child in this.Controls) {



                if ((child.ID =3D=3D fragmentName) && (child is 

Fragment)) {



                    return ((Fragment) child).Content;

                }

            }



            // If the fragment is not in the children collection,

attempt to

            // resolve it from a parent page to see if it is inherited



            if (this.BasedOn !=3D null) {



                Control basepage =3D page.LoadControl(basedOn);



                if (basepage =3D=3D null) {

                    throw new Exception("Couldn't load base page: " +

basedOn);

                }



                foreach (Control child in basepage.Controls) {



                    if (child is FragmentHolder) {

                        return ((FragmentHolder)

child).LoadFragmentTemplate(page, fragmentName);

                    }

                }

            }



            throw new Exception("Cannot find " + fragmentName + "

fragment!");

        }



        protected override void CreateChildControls() {

           

            // Load "main" fragment of page -- this is the entrypoint

            // for the page and controls overall page rendering



            ITemplate maintemplate =3D LoadFragmentTemplate(Page, 

"main");





            // Instantiate "main" fragment and insert it into the page

tree



            maintemplate.Initialize(this);

        }

    }







    // The below custom ControlBuilder implementation enables page

developers to

    // drop <dell:fragment> sections within a <dell:fragmentholder>

section

    // without having to have "runat=3Dserver" attributes on them.



    public class FragmentBuilder : ControlBuilder {



        public override Type GetChildControlType(string tagName,

IDictionary attribs) {



            if (tagName.ToLower().EndsWith("fragment")) {

                return typeof(Fragment);

            }



            return null;

        }

    }

}



<--



If you look at the FragmentBuilder - it takes care that there is no need

for runat=3D"server".



The problem is that the names the controls get in the generated code are

somehow funny. something like PAGENAME_Ctrl22. Might bee (its all

undocumented) that I need to extend the FragmentBuilder, but how?



Thomas Tomiczek







-----Original Message-----

From: Rob Howard [mailto:rhoward@m...]

Sent: Freitag, 6. Oktober 2000 16:36

To: ASP+

Subject: [aspx] RE: Need help on landling templates in a WebControl.





Hi Thomas,



I believe you need to add some more code to the control to render the

textbox within DkWeb:Fragment using templates. I didn't have time to

write an example, but take a look at the ASP+ quickstarts "Authoring

Custom Contorls" section (towards the bottom of the page).



The TextBox control is created as child control of the parent. Without

templates (when it's only a simple composite control), you can access

the TextBox control as follows:



 void Page_Load(){

   TextBox ctlSurname =3D (TextBox)

ContentLeftTop.FindControl("ctlSurname");

   ctlSurname.Text =3D "Hello from ctlSurname";

 }



another problem, you need to mark DkWeb:Framgment with a runat=3Dserver

property:



        <DkWeb:Fragment id=3D"ContentLeftTop" runat=3Dserver> 



Hope that helps.



Thanks,

Rob







office  xxx.xxx.xxxx  | cell  xxx.xxx.xxxx  | fax  xxx.xxx.xxxx  (attn:

rhoward)



-----Original Message-----

From: Thomas Tomiczek [mailto:thona@g...]

Sent: Friday, October 06, 2000 2:37 AM

To: ASP+

Subject: [aspx] Need help on landling templates in a WebControl.







Hello,



I have a very simpla WebControl (actually written by Scott Guthrie [ :-)

] that I need to extend.



Its code is:

-->

    public class Fragment : Control {



        private ITemplate content =3D null;

   

        public ITemplate Content {

           

            get {

                return content;

            }

            set {

                content =3D value;

            }

        }

    }

<--



Now, my problem is that when I use this control such as in

-->

        <DkWeb:Fragment id=3D"ContentLeftTop">

                <template name=3D"Content">

                        <asp:TextBox id=3D"ctlSurname" runat=3D"server"

Colums=3D"20"  MaxLength=3D"20" TextMode=3D"SingleLine" width=3D"100%"/>



                </template>

        </DkWeb:Fragment>

<--

I can not access the Textbox by its Id. Normally there is - on the page

- a variable generated whose name is the ID. In this case, the Name is

somehow composed by the name of the page plus another verb plus a number

- which is making it impossible to access the control, because the

number can change when the template is edited.



On the bad side: all the relevant parts of the documentation seem "still

to come".



Now, anyone has any knowledge on how I can take handle this? What I

actually want is that the above textbox is accessible from Script by its

id as would normally be the case.



Scott, if you read this - this is a similar request to the email I sent

to you yesterday, just that the email was longer and contained the

complete generated source for a page.



Any help is greatly appreciated.



Thomas Tomiczek



---



---



---



---







  Return to Index