Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to extend control to add custom html tag ?

Reply
Thread Tools

How to extend control to add custom html tag ?

 
 
timor.super@gmail.com
Guest
Posts: n/a
 
      12-18-2007
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.
 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      12-18-2007
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> How can I render such html code?


http://msdn2.microsoft.com/en-us/lib...01(VS.80).aspx


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

 
Reply With Quote
 
 
 
 
timor.super@gmail.com
Guest
Posts: n/a
 
      12-18-2007
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

On 18 déc, 11:53, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> > How can I render such html code?

>
> http://msdn2.microsoft.com/en-us/lib...01(VS.80).aspx
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      12-18-2007
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

On 18 déc, 11:53, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
>>> How can I render such html code?

>>
>> http://msdn2.microsoft.com/en-us/lib...01(VS.80).aspx
>>

> 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...


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

 
Reply With Quote
 
timor.super@gmail.com
Guest
Posts: n/a
 
      12-18-2007
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 ?



On 18 déc, 12:26, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> On 18 déc, 11:53, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
>
> > <(E-Mail Removed)> wrote in message

>
> >news:(E-Mail Removed)...

>
> >>> How can I render such html code?

>
> >>http://msdn2.microsoft.com/en-us/lib...01(VS.80).aspx

>
> > 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...
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


 
Reply With Quote
 
Peter Bucher [MVP]
Guest
Posts: n/a
 
      12-18-2007
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.

--
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


 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      12-18-2007
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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 ?


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/UploadF...BoxesFT_1.aspx


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

 
Reply With Quote
 
timor.super@gmail.com
Guest
Posts: n/a
 
      12-18-2007
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,



On 18 déc, 14:07, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> > 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 ?

>
> 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/Upload..._ListBoxesFT_1...
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


 
Reply With Quote
 
Peter Bromberg [C# MVP]
Guest
Posts: n/a
 
      12-18-2007
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


"(E-Mail Removed)" wrote:

> 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.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
HTML.Tag.BASE same as HTML.Tag.A carlbernardi@gmail.com Java 1 11-29-2006 03:41 AM
Visual Studio 2005 html-view does not recognize the generated html-tag of a custom control Rolf Welskes ASP .Net 3 10-06-2006 06:49 PM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Controlling html/xml tag of custom control from control code henrique de souza ASP .Net Building Controls 0 04-23-2004 02:40 PM



Advertisments