Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Adding a control to a custom web control

 
Thread Tools Search this Thread
Old 09-10-2005, 11:10 AM   #1
Default 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.



Web Team @ Borough of Poole
  Reply With Quote
Old 09-10-2005, 03:39 PM   #2
Scott Allen
 
Posts: n/a
Default Re: Adding a control to a custom web control
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"
<> 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.




Scott Allen
  Reply With Quote
Old 09-10-2005, 09:25 PM   #3
aa7im
 
Posts: n/a
Default Re: Adding a control to a custom web control
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



aa7im
  Reply With Quote
Old 09-12-2005, 01:01 PM   #4
Web Team @ Borough of Poole
 
Posts: n/a
Default Re: Adding a control to a custom web control
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.



Web Team @ Borough of Poole
  Reply With Quote
Old 09-12-2005, 04:28 PM   #5
Scott Allen
 
Posts: n/a
Default Re: Adding a control to a custom web control
On 12 Sep 2005 05:01:23 -0700, "Web Team @ Borough of Poole"
<> 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
<asplaceHolder> 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/


Scott Allen
  Reply With Quote
Old 09-14-2005, 02:02 AM   #6
aa7im
 
Posts: n/a
Default Re: Adding a control to a custom web control
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");
}
}



aa7im
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically added TreeNode Control not render my custom attribute venkyzealous Software 0 05-10-2008 03:46 PM
Custom control dropdownlist - need advice tcstom Software 0 04-18-2008 11:28 AM
Mind Control and CIA'S BOURNE IDENTITY PLOT soleilmavis@gmail.com DVD Video 2 08-03-2007 09:54 PM
Getting error in Custom control ShakilaRahmanLaboni Software 2 08-01-2007 02:38 PM
FS: JP1 cable to program your universial remote control, now youcan control anything you want! Mike DVD Video 0 07-15-2005 02:46 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46