473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Adding a control to a custom web control

Hi All,

Can someone please explain how I go about adding a control (Say for
example a panel) to a custom web control.

I've tried this:
Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
Dim EditPanel As New System.Web.UI.webcontrols.Panel
EditPanel.Attributes.Add("contenteditable", "")
EditPanel.BorderColor = System.Drawing.Color.AliceBlue
Me.Controls.Add(EditPanel)
End Sub

The panel doesnt seem to get written to the page.

I'm trying to get to the point where my user can enter some text into
the panel, which I can then get out of the control when they click
save/update/whatever.

Thanks!

Simon.

Nov 19 '05 #1
5 1597
I'd suggest moving that code into the Init event for the control, or
perhaps the Load event. The Render event is a bit late in the process
to be adding controls, and you'd need to call the base class Render or
RenderChildren method to get any HTML spit out.

--
Scott
http://www.OdeToCode.com/blogs/scott/
On 10 Sep 2005 03:10:45 -0700, "Web Team @ Borough of Poole"
<we*********@poole.gov.uk> wrote:
Hi All,

Can someone please explain how I go about adding a control (Say for
example a panel) to a custom web control.

I've tried this:
Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
Dim EditPanel As New System.Web.UI.webcontrols.Panel
EditPanel.Attributes.Add("contenteditable", "")
EditPanel.BorderColor = System.Drawing.Color.AliceBlue
Me.Controls.Add(EditPanel)
End Sub

The panel doesnt seem to get written to the page.

I'm trying to get to the point where my user can enter some text into
the panel, which I can then get out of the control when they click
save/update/whatever.

Thanks!

Simon.


Nov 19 '05 #2
This whole idea isn't going to work as easy as you want. Just by
setting the panels "ContentEditable" attribute to true will not cause
the data entered to be posted back the server. To make this work you
will need to load the content that someone is entering into the
contenteditable div into a hidden variable (using javascript) on the
page and then get the value from there. You would be better searching
and downloading a control that already does this like:

http://www.freetextbox.com

Nov 19 '05 #3
aa7im - I understand that adding ContentEditable is not going to write
my code for me. It simply says to the browser that the client can
change the innerHTML of the control.

I hear what you say about moving the editied HTML into a hidden
variable, which is exactly how our current ASP based editor works. I
can easily write the javascript to do this, but the hidden form field
still needs to be accessible as a server side control, so that I can
get my control to return the value of the editied text.

Scott - I'll try what you suggest, any ideas how I control where the
panel is out put to on the page?

Thanks,
Simon.

Nov 19 '05 #4
On 12 Sep 2005 05:01:23 -0700, "Web Team @ Borough of Poole"
<we*********@poole.gov.uk> wrote:

Scott - I'll try what you suggest, any ideas how I control where the
panel is out put to on the page?

If you want to inject the panel into the page dynamically and control
the position precisely, then the best solution is to put an
<asp:PlaceHolder> control on the page.

During the Load or Init event use the code you have in the Render
method to create the Panel and add it to the PlaceHolder object's
Controls collection.

Scott Mitchell has some example in this article:
http://aspnet.4guysfromrolla.com/articles/081402-1.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/
Nov 19 '05 #5
Ok...

So are trying to create a custom web control?

You can just inherit from the WebControl class

public class MyControl:WebControl
{
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Span;
}
}

protected override void Render(HtmlTextWriter writer)
{
writer.AddAttribute("contenteditable","on");
}
}

Nov 19 '05 #6

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

Similar topics

9
by: James Geurts | last post by:
Hey all... I posted this in the vs.net ide group too, but people are not answering, so I figured that it might be more appropriate here. I'm not sure if I'm adding a designer to my code properly. ...
2
by: Stephen Lambie | last post by:
Hi, I want to develop a custom checkbox. I want to use the existing checkbox in a custom control where I use the disabled state as a third state. I need to be able to detect mouse or click...
0
by: sonic | last post by:
hello, I have this custom datagrid control, that inherits from DataGrid. In addition to datagrid, I am adding a "status" table under it, and another html button, which will trigger a new row. ...
18
by: Praveen Ramesh | last post by:
Hi, Is there any way to add the @Assembly reference to the aspx files programmatically from inside a custom control (when it gets dropped on to the page from the toolbox)? I have a custom...
3
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
3
by: Jonathan Wood | last post by:
I could really use some help on this. First of all, I want to create a Web control where I render the control completely from scratch based on information from a database. In the book...
11
by: Pete Kane | last post by:
Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would contain tab pages of my own classes, I know you can achieve this with...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
12
by: Bob Jones | last post by:
I have an odd business requirement and I think that the implementation is not correct in the terms of OOP development. Any help on the concepts would be very appreciated! We currently have a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.