Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

How to extend control to add custom html tag ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
timor.super@gmail.com - 18 Dec 2007 10:18 GMT
Hi group,

the aspx statement :
<asp:TextBox ID="testTB" runat="server" Text="My test" />
generate html :
<input name="testTB" type="text" value="My test" id="testTB" />

Imagine I want to create a custom web control, extending the TextBox
control to add a custom hidden value.
Something like :

<MyNamespace:MyTextBox ID="testTB" runat="server" Text="My test"
HiddenValue="a value" />

that can generate such html code :
<input name="testTB" type="text" value="My test" id="testTB" />
<input name="hid_testTB" type="hidden" value="a value"
id="hid_testTB" />

How can I render such html code ? (without having to rewritte all
using writer.WriteBeginTag , and other writer.WriteAttribute)

Something like

protected override void ?? (...)
{
   RenderTheBaseControl();
   RenderTheAddedHiddenField();
}

How can I do ?

Thanks in advance for your help.

S.
Mark Rae [MVP] - 18 Dec 2007 10:53 GMT
> How can I render such html code?

http://msdn2.microsoft.com/en-us/library/ms228301(VS.80).aspx

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

timor.super@gmail.com - 18 Dec 2007 11:03 GMT
I want my own custom control to be able to add both TextBox control
and HiddenField, not adding 2 control in my page.

This is an example, maybe later I would like to do something
different, but I would like to understand how I can override the
render by adding html code

> <timor.su...@gmail.com> wrote in message
>
[quoted text clipped - 7 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net
Mark Rae [MVP] - 18 Dec 2007 11:26 GMT
On 18 déc, 11:53, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:
> <timor.su...@gmail.com> wrote in message
>
[quoted text clipped - 6 lines]
> I want my own custom control to be able to add both TextBox control
> and HiddenField, not adding 2 control in my page.

Apologies, but I don't understand what the problem is...

You can have as many controls as you like in your UserControl - see examples
here:
http://www.15seconds.com/issue/020319.htm

If you want to create a UserControl which has a TextBox and a HiddenField,
then create a UserControl with a TextBox and a HiddenField - when you add it
to your page and set the various properties, it will render the HTML you
want...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

timor.super@gmail.com - 18 Dec 2007 12:20 GMT
Thanks for your answer, but I don't want to use UserControl because I
need some specific uses, such as RaiseCallbackEvent.
That's why I was thinking of a custom webcontrols, inheriting from
TextBox
And somewhere in a render method, render the TextBox and render the
HiddenField, but I don't know how

You see ?

> <timor.su...@gmail.com> wrote in message
>
[quoted text clipped - 26 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net
Mark Rae [MVP] - 18 Dec 2007 13:07 GMT
> Thanks for your answer, but I don't want to use UserControl because I
> need some specific uses, such as RaiseCallbackEvent.
[quoted text clipped - 4 lines]
>
> You see ?

No, I'm afraid I don't... There's nothing preventing you from using
RaiseCallbackEvent in a UserControl - here's an example of how to do it with
a UserControl which contains two ListBox controls:
http://www.c-sharpcorner.com/UploadFile/LivMic/Callback_ListBoxesFT_111212006084
429AM/Callback_ListBoxesFT_1.aspx


Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

timor.super@gmail.com - 18 Dec 2007 13:43 GMT
Thanks both for your help,

The Peter's solution helps me to understand that it's very simple to
play with writer.
Mark's solution help me reconsidering what I want.

I think I will find what I want

Thanks for your help.

Best regards,

> <timor.su...@gmail.com> wrote in message
>
[quoted text clipped - 16 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net
Peter Bucher [MVP] - 18 Dec 2007 12:42 GMT
Hello Timor

Iam not sure wether i understood or not ;-)
Its possible to do something like:

protected override Render(object sender, HtmlTextWriter writer) {
   // Render the TextBox (Base Control)
   base.Render(writer);

   // Render the HiddenField
   this.RenderMyHiddenField(writer);
}

protected void RenderMyHiddenField(HtmlTextWriter writer) {
   // Render....
}

In your new methode, you can render the hiddenfield using the "writer"
object.

Signature

Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET

Peter Bromberg [C# MVP] - 18 Dec 2007 19:29 GMT
It isn't really clear from your post what the goal is, but it's very easy to
add attributes to any ASP.NET control:

this:
protected void Page_Load(object sender, EventArgs e)
       {
           this.TextBox1.Attributes.Add("hiddenField", "blahblah");
       }

would render like this:

 <input name="TextBox1" type="text" id="TextBox1" hiddenField="blahblah" />
--Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com 

> Hi group,
>
[quoted text clipped - 31 lines]
>
> S.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.