473,778 Members | 5,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to extend control to add custom html tag ?

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:My TextBox 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_testT B" type="hidden" value="a value"
id="hid_testTB " />

How can I render such html code ? (without having to rewritte all
using writer.WriteBeg inTag , and other writer.WriteAtt ribute)

Something like

protected override void ?? (...)
{
RenderTheBaseCo ntrol();
RenderTheAddedH iddenField();
}

How can I do ?

Thanks in advance for your help.

S.
Dec 18 '07 #1
8 2224
<ti*********@gm ail.comwrote in message
news:aa******** *************** ***********@18g 2000hsf.googleg roups.com...
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

Dec 18 '07 #2
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]" <m...@markNOSPA Mrae.netwrote:
<timor.su...@gm ail.comwrote in message

news:aa******** *************** ***********@18g 2000hsf.googleg roups.com...
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
Dec 18 '07 #3
<ti*********@gm ail.comwrote in message
news:98******** *************** ***********@o42 g2000hsc.google groups.com...

On 18 déc, 11:53, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
<timor.su...@gm ail.comwrote in message

news:aa******** *************** ***********@18g 2000hsf.googleg roups.com...
>>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

Dec 18 '07 #4
Thanks for your answer, but I don't want to use UserControl because I
need some specific uses, such as RaiseCallbackEv ent.
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]" <m...@markNOSPA Mrae.netwrote:
<timor.su...@gm ail.comwrote in message

news:98******** *************** ***********@o42 g2000hsc.google groups.com...

On 18 déc, 11:53, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
<timor.su...@gm ail.comwrote in message
news:aa******** *************** ***********@18g 2000hsf.googleg roups.com...
>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
Dec 18 '07 #5
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(wri ter);

// Render the HiddenField
this.RenderMyHi ddenField(write r);
}

protected void RenderMyHiddenF ield(HtmlTextWr iter 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
Dec 18 '07 #6
<ti*********@gm ail.comwrote in message
news:83******** *************** ***********@l32 g2000hse.google groups.com...
Thanks for your answer, but I don't want to use UserControl because I
need some specific uses, such as RaiseCallbackEv ent.
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
RaiseCallbackEv ent 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

Dec 18 '07 #7
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]" <m...@markNOSPA Mrae.netwrote:
<timor.su...@gm ail.comwrote in message

news:83******** *************** ***********@l32 g2000hse.google groups.com...
Thanks for your answer, but I don't want to use UserControl because I
need some specific uses, such as RaiseCallbackEv ent.
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
RaiseCallbackEv ent 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
Dec 18 '07 #8
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(objec t sender, EventArgs e)
{
this.TextBox1.A ttributes.Add(" hiddenField", "blahblah") ;
}

would render like this:

<input name="TextBox1" type="text" id="TextBox1" hiddenField="bl ahblah" />
--Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"ti*********@gm ail.com" 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:My TextBox 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_testT B" type="hidden" value="a value"
id="hid_testTB " />

How can I render such html code ? (without having to rewritte all
using writer.WriteBeg inTag , and other writer.WriteAtt ribute)

Something like

protected override void ?? (...)
{
RenderTheBaseCo ntrol();
RenderTheAddedH iddenField();
}

How can I do ?

Thanks in advance for your help.

S.
Dec 18 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3273
by: Eric Anderson | last post by:
I am trying to use XSLT to extend XHTML so that I can have custom widgets. For example I have a calendar control. Whenever I put the following in the psudo-XHTML doc: <calendarbox name="mycal"/> I get a nice xhtml text box with a calendar icon beside it. When the calendar icon is clicked a calender pops up to allow the user to choose the date. Then the value chosen is stuck in the xhtml text field and can be submitted with the form. I...
3
2867
by: __PPS__ | last post by:
Hello, I'm newbe to xml/dtd (and probably I don't use all the termins correctly). I'm writing an application that parses xhtml file with custom elements and splits it into 2 parts - valid xhtml1.0 and a script file. basicly I have this: .... <MYML:form action=""> <MYML:input type="text"> ... ... </MYML:form> ....
3
10837
by: Joe Bloggs | last post by:
Does anyone know if its possible to pass parameters or the values of Request.QueryString from a web page to a custom control class? I'm using a C# Web Application. For Example I have Web Page1 which has to parameters passed to it from another Web page Parameter # 1 dbid and Parameter # 2 reportid. I know that I can access the values of the parameters from the code behind .aspx.cs using Request.QueryString so
19
2989
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and provide an open TD with a DIV in it for the content of this formlet. (The DIV is for DHTML to hide and show the content) I've created a web page showing step by step the two problems I'm encountering. This problem is much easier to see than it...
6
2691
by: jk | last post by:
Looking through WebUIValidation.js, I discovered that the standard validators don't cater for non-numeric date formats (e.g. dd-MMM-yyyy) which I would like to do To keep code to a minimum, I would like to extend the existing validator to handle other common date formats and still be able to do both client and/or server side validation as normal. Unfortunately, I am unable to get the extended code to ever be called I implemented the...
4
1789
by: DKode | last post by:
I have developed a custom server control that displays a login page that authenticates against AD. The server control works fine, but now I am trying to figure out the best way to output custom html. The HTML output for the server control changes for each application I include the server control in. At first I thought about making an html file and just including it, but this won't work because with the custom html I output two textboxes...
11
3288
by: Nick Gilbert | last post by:
Hi, How can I create a custom control which will wrap its content in a header and footer? eg: Is it possible to create a .NET user control which can surround other controls? eg: <my:RoundedCornerBox id=foo runat=server>
5
4127
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like to wrap the control in the proper control type - which is also a container. At design time I want to be able to turn this : <my:container> <asp:textbox />
4
2492
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried unsuccessfully in creating the whole pane as a user control and have succeeded in adding the pane and then dynamically adding the content which is a user control to the pane, dynamically within the page. However I would like to have a single pane...
0
9629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9470
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8957
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4033
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.