trying to understand how an ITemplate works

Hello,

 I have been looking on google and around to try to grasp the functionallity of a ITemplate.

What i want first of all is that my user (after dragging the control onto an asp.net page) fills in some html in a layout field.

example:

<
cc1:EmailControl ID="EmailControl1" runat="server">
<EmailOwnerLayout>
This email was sent on <b>{sent}</b> from <b>{name}</b> (<b>{email}</b>).
<br /><br />
{message}
</EmailOwnerLayout>
</cc1:EmailControl>

When he then clicks on send, i want to get that html code into a string (or similar) so that i can parse it and add the text to an email.

So i added this to the codebehind, trying to work out how to get the code that is inside the ITemplate into my string:

public class EmailLayoutContainer : Control, INamingContainer
{
internal EmailLayoutContainer()
{
}
public string GetLayout()
{
   //this.Context.   // Return the layout somehow
}
}

And then to the main class

ITemplate emailLayoutTemplate = null;
[TemplateContainer(typeof(EmailLayoutContainer))]
[
PersistenceMode(PersistenceMode.InnerProperty) ]
public ITemplate EmailLayout
{
get
{
   
return emailLayoutTemplate;
}
set
{
    emailLayoutTemplate =
value;
}
}

void mButton_Command(object sender, CommandEventArgs e)
{
EmailLayoutContainer mCon = new EmailLayoutContainer("");
emailOwnerLayoutTemplate.InstantiateIn(mCon);
string strLayout = mCon.GetLayout();

0
pafo
12/12/2008 12:00:28 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

1 Replies
536 Views

Similar Articles

[PageSpeed] 32

Hi pafo,

Based on my experience, if you want to fill in some HTML code in a layout field when you drag it onto ASP.NET Page. you should do it in Render event (if you create a custom control). Such as:

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            base.Render(writer);
            writer.Write("&lt;a href=\"#\"&gt;my onclick</a>");
        }

 For the principle of ITemplate Interface. Here is a code block I have done, please refer to the following code:

//Code

public class MyTemplate : ITemplate
{

    public void InstantiateIn(Control container)
    {
        Literal lbl = new Literal();
        lbl.DataBinding += new EventHandler(lbl_DataBinding);//Here is the key point
        container.Controls.Add(lbl);
    }

    private void lbl_DataBinding(object sender, EventArgs e)
    {
        Literal lbl = (Literal)sender;
        if (DataBinder.Eval(((DataListItem)lbl.NamingContainer).DataItem, "HaveImg").ToString() == "False")
        {
            lbl.Text = "&lt;a href=\"" + DataBinder.Eval(((DataListItem)lbl.NamingContainer).DataItem, "Link").ToString() + "\"&gt;" + DataBinder.Eval(((DataListItem)lbl.NamingContainer).DataItem, "Name").ToString() + "&lt;/a>";
        }
        else
            lbl.Text = "&lt;a href=\"" + DataBinder.Eval(((DataListItem)lbl.NamingContainer).DataItem, "Link").ToString() + "\"&gt;<img alt=\"" + DataBinder.Eval(((DataListItem)lbl.NamingContainer).DataItem, "Name").ToString() + "\" src=\"" + DataBinder.Eval(((DataListItem)lbl.NamingContainer).DataItem, "ImgUrl").ToString() + "\" border=\"0\" width=\"95\" height=\"38\" /></a>";
    }
}
//Call Method: datalist.ItemTemplate = new MyTemplate();

At the same time, Please refer to this article to know more about it.

http://msdn.microsoft.com/en-us/library/system.web.ui.itemplate.aspx

http://www.codeproject.com/KB/user-controls/TemplatedControl.aspx

http://www.codeproject.com/KB/aspnet/Simple_Template_Parser.aspx


Gary yang - MSFT
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Gary
12/16/2008 3:34:34 AM
Reply:

Similar Artilces:

Shell not working in web form but working with windows forms.
Hi! I want to run some exe files (Exa: Internet explorer) using shell command in asp.net. Its not working if its a web form. But working fine with a windows form. Pls. extend ur help. Thanx. What are you expecting to happen? How are you trying to run the exe files? Where do you expect it to run? Anything run through server side code will run on the server, and in an invisible window, at that. The program will run under the security context of the ASPNET user by default, and so likely will not have the proper authority to do much of what you want, unless you midify its rights...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

dropdowndw properties not working on .net web forms 11.5
Hi. I am using a datawindow that has many dropdownDW, where i would like the dropdown portion show more data then when something is selected. I would use the width percentage in of the dropdown to set this in a application. But when i set this property or any other size properties, on the web it dosn't listen and just defaults and will only show the dropdown data the width of the dropdown. Stuff like size dosn't work either. I could under stand that since it is on the web it cannot do these things. But we also have datawindow.net and have a .net application us...

error trying to create web form from visual studio.net
I get the following message when I try to create a web form from visual studio. Visual Studio.NET has detected that the specified web server is not running ASP.NET version 1.1. You will be unable to run ASP.NET web applications or services. I downloaded and installed ASP.NET version 1.1. Why am I getting this message? Thanks, Keith Stallings Try running aspnet_regiis -i from the .Net Framework's bin directory to see if it corrects the problem....

System.web.UI doesn't work in VB.Net Form?
 Hi, I downloaded a little example recently and tried converting it to VB.Net.  Surprisingly I found that while my VB Web projects and CSharp Windows Form projects work with System.web.UI, VB Windows Forms don't seem to. Is there any way I can use System.web.UI features with a windows form? This is the code I'm trying to convert to VB:   using System.IO;using System.Web.UI.WebControls;using System.Web.UI;// render the DataGrid control to a fileusing(StreamWriter sw = new StreamWriter(textBox1.Text)){ using(HtmlTextWriter hw = new HtmlTextWriter(sw)) { g...

I am trying to access links off of the web page at the bottom of this email. They work in Internet Explorer just fine. I have tried this on 2 different computers and the links do not work. Why? Tha
I am trying to access links off of the web page at the bottom of this = email. They work in Internet Explorer just fine. I have tried this on 2 = different computers and the links do not work. Why? Thanks. =20 =20 =20 Brenda Sharpmack Watson Chapel School District Technology Coordinator 870 - 879 - 7206 (office) 870 - 556 - 0640 (cell) 870 - 879 - 1710 (fax) ( http://wc-web.k12.ar.us/school%20sites/WC%20SCHOOL%20SITES%20INDEX.htm = ) Brenda Sharpmack said this on 4/3/2009 11:30 AM: > I am trying to access links off of the web page at the bottom of this email. They w...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

Web form works well, but not on web thru PDA...
I've been working on some web forms that seem to work beautifully (thankfully).  Unfortunately, when a user attempts to access these forms from their blackberry or pocketpc it never works.  Is there something I should be doing to enable my web forms to work on the web for pda's also?  Here's my link... http://glmcv.glmoyer.com/miamilakesweb/streetlighttest/updatestreetlightinfo.aspx...

.Net Web Form & Web Service Deployment
Hi all I have written some test web services and some web form applications and deployed them to my IIS. That's fine but I now want to deploy them to my real IIS server. I have created an msi for each but the problem is I seem to only be able to deploy to the default web site. Our default web site is turned off and instead we use several other sites. Does anybody happen to if Powerbuilder 11 supports non default web sites? If not do I need to hack the msi and if so can anybody suggest a suitable tool. I have Orca but it's not very friendly. Unless of course I knew exactly w...

Web forms and mobile web forms
Hey everyone, I am looking to develope a web site that depending on the device connecting to it, it will display a certain page. In this case im looking to create a web and wap version of the same project. I have the Web forms version finished using ASP.NET and C# and I am wondering how to create the mobile web form and incorporate it in the project. In the project folder, can I just add a mobile web??? But what about displaying device specific pages?? Cheers -Dudach Yes, you can add mobile web forms and controls to your Web Application project. No problem. For device/br...

How to Make Web Forms from other Web Forms
In putting together an ASP.NET application for a biz application, we have come to the point where there are three different types of basic forms which have, for the most part, been perfected. Now its is a matter of cloning those forms for various uses and modifying or adding code to suit the particular need. Copy and paste works OK, but there is a lot of changing of certain words, etc. Is there a way in ASP.NET to take these basic forms, turn them into classes or templates, create forms from them, then add or overwrite code? ? (Anybody who is a Vis Fox Pro programmer would know imme...

Understanding Web Form System.Web.UI.Page.ProcessRequest
Hello all ... I'm working with a third-party product that monitors .NET and ASP.NET performance.  This product monitors performance times for "entry points" ... essentially how long it takes to load an .aspx page, etc.  Pretty slick. The "entry point" they use to start tracking time on a Web page is System.Web.UI.Page.ProcessRequest      I looked this up in the docs, and it says this is one of the features available in ASP.NET that really isn't intended for developers to use.  OK, fair enough.  I as a developer shouldn't use it....

Problem with Web Content Form in a Web Application when trying to attach masterpage
Hi,When I try to create a web content form and select to use the masterpage below Visual Studio 2008 freezes. It works with any other masterpage and everything else works fine in Visual Studio. Everything compiles and runs. To replicate this problem put the below files in a new web application and then try and create a web content form and use the master page. I have tried this on a number of different machines and still have the same problem. I have used the masterpage in other projects and still falls over so I know its not the sln or proj files, and when its been deployed using our CI ser...

For interrupting.web form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form
Web Form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form ! Because of my pool English, if you can't see , I will explain more ! ThanksGambler is the real life I guess you mean when form grows it also grow parent div element. This is normal. If you want div to stay fixed size and rather clip the form and maybe show a scrollbar, look at overflow property in CSS.Thanks------------------------------------------------------------This posting is provided "AS IS" with no warranties, and confers no ...

Web resources about - trying to understand how an ITemplate works - asp.net.web-forms

Resonate Social For Facebook Helps Advertisers Understand Users’ Motivations
Why do Facebook users make the decisions they make? Resonate wants to help advertisers find out, so the digital marketing outfit launched Resonate ...

Facebook PMD Gigya releases Consumer Insights to better understand user identities
... allows marketers to easily query Gigya’s Identity Storage database and tie identity information with key performance indicators to understand ...

Genius by Rap Genius — Search and understand the meaning of song lyrics, poetry, literature, and news ...
Get Genius by Rap Genius — Search and understand the meaning of song lyrics, poetry, literature, and news on the App Store. See screenshots and ...

All sizes - Understand Abundance & Breath - Flickr - Photo Sharing!
Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to ...

Kate Micucci & Tony Thaxton - "Puppets Understand" - YouTube
Subscribe for more Nerdist Presents: http://nerdi.st/subscribe Written and Performed by KATE MICUCCI & TONY THAXTON Watch Duo: http://youtu.be/Tj5RLliHNMQ ...

Scientists continue search to understand Mers
The Mers coronavirus continues to confound scientists. To better understand the disease and determine where it comes from, a new project set ...

Explainer Video of the Day: Author John Green Helps You Understand Boko Haram
... in the news, but the situation in Nigeria with the Islamist terrorist group Boko Haram often gets overlooked and can be difficult to understand. ...

The Aussie rules love affair and one who can't understand it
Football (the AFL variety) and I have always had a tumultuous relationship. I've never really understood its allure, but it's always been there, ...

14 Accounting Terms Everyone In Small Business Needs To Understand
Like any profession, accounting has what seems to be impenetrable jargon to outsiders. But, also like most professions, the jargon is just shorthand ...

Tony Abbott doesn't understand the China challenge
The Australian government's new attitude towards China's foreign policy underestimates that country's determination to change the geopolitical ...

Resources last updated: 1/20/2016 6:31:13 AM