Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Rendering literal and serveral controls nested in web control at design time

Reply
Thread Tools

Rendering literal and serveral controls nested in web control at design time

 
 
Stephen Miller
Guest
Posts: n/a
 
      01-02-2004
I have a custom web control that I want to be able to render nested
literal HTML and or server controls. When deployed on an aspx page, my
control might look like:

<cc1:myControl RunAt="server">
<b>literal content</b>
<asp:RequiredFieldValidator id="valRequired" runat="server"
ErrorMessage="This field is Required."
ControlToValidate="txtRequired">*</asp:RequiredFieldValidator>
<asp:TextBox id="txtRequired" runat="server" MaxLength="50"
width="200px"></asp:TextBox>
<asp:Button id="cmdTest" runat="server" Text="Generate
event"></asp:Button>
</cc1:myControl>
<asp:Label id="lblResult" runat="server">lblResult</asp:Label>

I have figured out that at a minumum, I need to:
1. Add the design time attribute '[ParseChildren(false),
PersistChildren(true)]', which enables literal to be displayed in run
time.
2. Implement the INamingContainer interface to listen to events
generated by child controls
3. Implement the IPostBackDataHandler interface to automatically load
post back data

As such, my barebones control currently looks like:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Collections.Specialized;

namespace myCustomControl {

[ToolboxData("<{0}:myControl runat=server></{0}:myControl>")]
[ParseChildren(false), PersistChildren(true)]
public class myControl : WebControl, INamingContainer,
IPostBackDataHandler {

protected override void Render(HtmlTextWriter output){
output.Write("<b>before</b><br /><hr><br />");
base.Render(output);
output.Write("<br /><hr><br /><b>after</a>");
}

bool IPostBackDataHandler.LoadPostData(string strPostDataKey,
NameValueCollection postDataCollection) {
return true;
}
void IPostBackDataHandler.RaisePostDataChangedEvent() {}
}
}

After much effort this is currently working ok in runtime and
importantly, the nested controls can generate postback events outside
the control (ie. clicking the button cmdTest triggers a onClick event
that can be used to update lblResult).

I have now turned to design time rendering of this control and have
hit a brickwall. I would like my control to render any nested ltereral
HTML or server control placed inside the control's <cc1:myControl>
tags. Ideally I should be able to drag and drop any control from the
toolbar onto my control, and it will automagically nest the control
and add the control to the aspx page. Conceptually I should be able to
drag and drop myControl and nest within a parent myControl.

I have done a lot of reading and trawling to find a technique to
render a design time interface with little luck. Can anyone provide
some tips/code?

Is there anyhing else I should consider in building my control?

Thanks,

Stephen
 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      01-02-2004
hi stephen, You need to associate your control with a ControlDesigner class.
Here on this example they are using the most basic features --should put you
on the right track.
http://msdn.microsoft.com/library/de...gnersample.asp



"Stephen Miller" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> I have a custom web control that I want to be able to render nested
> literal HTML and or server controls. When deployed on an aspx page, my
> control might look like:
>
> <cc1:myControl RunAt="server">
> <b>literal content</b>
> <asp:RequiredFieldValidator id="valRequired" runat="server"
> ErrorMessage="This field is Required."
> ControlToValidate="txtRequired">*</asp:RequiredFieldValidator>
> <asp:TextBox id="txtRequired" runat="server" MaxLength="50"
> width="200px"></asp:TextBox>
> <asp:Button id="cmdTest" runat="server" Text="Generate
> event"></asp:Button>
> </cc1:myControl>
> <asp:Label id="lblResult" runat="server">lblResult</asp:Label>
>
> I have figured out that at a minumum, I need to:
> 1. Add the design time attribute '[ParseChildren(false),
> PersistChildren(true)]', which enables literal to be displayed in run
> time.
> 2. Implement the INamingContainer interface to listen to events
> generated by child controls
> 3. Implement the IPostBackDataHandler interface to automatically load
> post back data
>
> As such, my barebones control currently looks like:
>
> using System;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.HtmlControls;
> using System.ComponentModel;
> using System.Drawing;
> using System.Globalization;
> using System.Collections.Specialized;
>
> namespace myCustomControl {
>
> [ToolboxData("<{0}:myControl runat=server></{0}:myControl>")]
> [ParseChildren(false), PersistChildren(true)]
> public class myControl : WebControl, INamingContainer,
> IPostBackDataHandler {
>
> protected override void Render(HtmlTextWriter output){
> output.Write("<b>before</b><br /><hr><br />");
> base.Render(output);
> output.Write("<br /><hr><br /><b>after</a>");
> }
>
> bool IPostBackDataHandler.LoadPostData(string strPostDataKey,
> NameValueCollection postDataCollection) {
> return true;
> }
> void IPostBackDataHandler.RaisePostDataChangedEvent() {}
> }
> }
>
> After much effort this is currently working ok in runtime and
> importantly, the nested controls can generate postback events outside
> the control (ie. clicking the button cmdTest triggers a onClick event
> that can be used to update lblResult).
>
> I have now turned to design time rendering of this control and have
> hit a brickwall. I would like my control to render any nested ltereral
> HTML or server control placed inside the control's <cc1:myControl>
> tags. Ideally I should be able to drag and drop any control from the
> toolbar onto my control, and it will automagically nest the control
> and add the control to the aspx page. Conceptually I should be able to
> drag and drop myControl and nest within a parent myControl.
>
> I have done a lot of reading and trawling to find a technique to
> render a design time interface with little luck. Can anyone provide
> some tips/code?
>
> Is there anyhing else I should consider in building my control?
>
> Thanks,
>
> Stephen



 
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
How can i download serveral files on one go? JimmySlam ASP General 1 04-10-2006 09:41 AM
traversing a hash two using serveral conditions Me Perl Misc 3 01-20-2006 12:37 PM
Rendering Server Controls in literal text =?Utf-8?B?Sm9l?= ASP .Net 14 10-24-2005 06:21 PM
render not rendering literal controls geoff ASP .Net Web Controls 1 04-17-2004 02:33 PM
What is the best way to pass a user identity between serveral ASP.NET web sites? Stan ASP .Net 6 08-22-2003 09:02 PM



Advertisments