Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 28th, 2007, 05:41 AM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom Controls

Hi

I've been reading my way through the Web Parts and Custom Controls in ASP.Net 2.0 book by Peter Vogel. I got to chapter 3 on building a custom control and got confuesed and need help!

What I'm trying to do is create a custom control to send Email! This control would have three text boxes:

1. Email address
2. Subject
3. Message

Each of these would have a corresponding title label and error label! There would also be a button to submit the form and run some validation against the fields.

I added each control to the controls collection in a CreateChildControls method which worked fine! My confusion came when I wanted to set the layout of the control.

What I want is to create a table with two columns. The first column on each row would contain the title label, the second would contain the text box with a whitespace after it and then the error label. The final row would be a merged cell containing the submit button.

However I'm really unsure of how to go about doing this. The book talks about overriding various render methods (render begin, render end etc) and using writer.RenderBeginTag(). Unfortunatly the book does say you can do this and says you break it up into 3 sections:

1. Write out the initial table tag
2. Render the constituent controls and their HTML
3. Write out the end table tag

but the book, nor the downloadable code examples show you how to do this and I can't work it out!

Can someone please help me out with this!?

Many thanks in advance

Ross

Reply With Quote
  #2 (permalink)  
Old June 28th, 2007, 09:28 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm no expert in custom controls, but you could try this:

When you add your controls in CreateChildControls, also add the formatting controls.

Create an HtmlControls.HtmlTable control and the necessary instances of HtmlControls.HtmlTableRow and HtmlControls.HtmlTableCell. Add your labels and textboxes to the cells and the cells to the rows and rows to the table to form the tabular layout, then add the table to the main Controls collection.


I think the approach indended by the book is to do this:
write out a chunk of html to start (i.e. <table>....<td>)
render the first row label
write out the next html chunk (</td><td>)
render the first row textbox
and so on and so forth until you get to
write out the end html chunk (</td></tr></table>)

Personally, I think the first approach is better because you can let the control render itself using the built in html controls so it's significantly easier to write. But that might not be the preferred way of creating custom controls. As I said, I'm no expert.

-Peter
Reply With Quote
  #3 (permalink)  
Old July 2nd, 2007, 05:07 PM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

I agree, I find I have fewer problems the more I can rely on the .NET class libraries. They tend to be easier to code and manipulate. But you can write it all out manually, if you have to.

I think you're only problem here is that you're expecting it to be harder than it is. And most of the time MS, makes it so. ;) But I think this time, it really is as simple as writing chunks of of table structure (e.g. "<table><tr><td>") and concatenating that in with the other controls in your custom control.

Good luck.

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Controls pro-logic C# 2008 aka C# 3.0 1 November 26th, 2008 10:55 AM
Custom Controls apry BOOK: Beginning ASP.NET 1.0 2 May 24th, 2004 12:04 AM
Custom Controls bmains ASP.NET 1.x and 2.0 Application Design 1 April 8th, 2004 06:26 PM
Custom Controls bmains VS.NET 2002/2003 3 February 5th, 2004 09:54 AM



All times are GMT -4. The time now is 10:44 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.