Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Urgent Q: 'correct' coding of a Webcontrol Designer driving me nuts...

Reply
Thread Tools

Urgent Q: 'correct' coding of a Webcontrol Designer driving me nuts...

 
 
Sky
Guest
Posts: n/a
 
      05-31-2004
Hello:
Have a problem that has been driving me nuts for a week. Should have reached
out for help sooner

If I edit the Text Property of an ASP:LABEL it immediately updates the IDE's
view.

But when I make a control, and a designer for it, give it a Text
Property...it doesn't.
The only way I can get it to update is to switch to HTML view, add a space
or tab to the file to ensure a DateTime change, save, and then return to the
page. Now it is updated.

Direction one:
I've looked at adding Attributes. That didn't seem to do it. Maybe I am
using the wrong ones but ...?

Direction two:
I've not found good documentation as to what CreateChildControls() is used
for, and when to override it without mucking up the ViewState, but I also
tried this approach:

public string Text {get {return _Text;}set {_Text
=value;CreatedChildControls = false;}

public override CreateChildControls(){
this.Controls.Clear();
HtmlGenericControl oSpan = new HtmlGenericControl("SPAN");
oSpan.InnerHtml = _Text;
this.Controls.Add(oSpan);
}

and see if that triggers it...nope as far as I can see. Plus, I'm not sure
when in the lifespan of a control it is called. although it is somewhere. Is
it before ViewState is unpacked? After? What are the rules to watch out for?
Should I be creating my child elements here, or use my own protected
_CreateElements() called from either Page_Load(), or override Render(),
depending on whether I am trying to track clicks etc?


I'm using VS2002 btw in case that means something -- but I don't think this
should be an issue (as the ASP:LABEL works correctly).

As for the designer, I don't know if that it the problem. But in just in
case, the Designer part looks in essense like:

public class XActControlDesigner : System.Web.UI.Design.ControlDesigner {
protected WebControl oControl;

public override void Initialize(IComponent qComponent) {
if(qComponent is Control) {try {base.Initialize (qComponent);oControl =
(WebControl)qComponent;}catch {}
}

public override string GetDesignTimeHtml() {


try {
oControl.BorderStyle = System.Web.UI.WebControls.BorderStyle.Dashed;
oControl.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
oControl.BorderColor =
System.Drawing.ColorTranslator.FromHtml("#C0C0FF") ;
return base.GetDesignTimeHtml();
}
catch(Exception E) {return GetErrorDesignTimeHtml(E);}
}

protected override string GetEmptyDesignTimeHtml(){
return string.Format("<div style='border:dashed 1px blue;'>No HTML to
render at this time.</div>");
}

protected override string GetErrorDesignTimeHtml(System.Exception E){
string tControlName = "[N/A]"; try {tControlName =
oControl.GetType().ToString();}catch {}
string tStackTrace = E.StackTrace.Replace(Environment.NewLine,"<br/>");
return string.Format("<div style='border:double 3px
red;font-family:Verdana,Tahoma, Arial;'><h4
style='margin:0;padding:0;'>Error</h4><br/>Could not Render Control
({0})<hr/><div style=\"font-size:8pt;font-family:'Courier New'\"><h5
style='margin:0;padding:0;'>Stack Trace
{1}</h5>{2}</div></div>",tControlName,tInitMsg,tStackTrace);
}



Anybody have ideas for what to do?

Thanks very very much.

PS: I do have one more question. The idea does not seem to process STYLE
tags, so if the Render() part ejects inline STYLE rules, it doesn't render
them. It only renders colors, etc. if the css is inline. ... But in the case
of making a RichEdit control, that has lots of buttons, this seems to be a
waste of bandwidth using "width:16px;height:16px;" etc. for every single
button when class=ICON was nice and sweet. Any ideas on how to get the IDE
to look like it will be in the final browser, exactly?

Thanks so much.
Sky


 
Reply With Quote
 
 
 
 
Sky
Guest
Posts: n/a
 
      05-31-2004
Correction:
Uh...As for part II of the last question (STYLES) etc. I just found out that
its not that it is not correctly processing CLASS versus inline CSS rules --
it's that if your control is using the Page.RegisterStartupScript() as I
was...you're going to wait all day. the Event doesn't seem to happen in the
IDE.

Therefore... Going to have to use some other mechanism to inject STYLE
tagged stuff into both the browser, AND the IDE...
Or not take care of it from there, just do it via the user adding it
manually to the page...

Hum.

And as for the first part of the problem... where I am at now is the
following:

a) Use CreateChildControls as before
b) override render and add the following lines:

if (this.Visible){
try {if (this.Site.DesignMode){this.ChildControlsCreated
=false;}}catch{}
this.EnsureChildControls();
base.Render();
}

That seemed to do it so that it continued to render as before in the
Browser...and now immediately rebuilt/repainted the control in the IDE upon
a change.

Whew.
Only question left is -- is this OK. Or can someone point out that this
route will completely mess up the control tree somehow?

Any feedback/confirmation/warnings people can give, thanks!

Sky


"Sky" <(E-Mail Removed)> wrote in message
news:Oy4$(E-Mail Removed)...
> Hello:
> Have a problem that has been driving me nuts for a week. Should have

reached
> out for help sooner
>
> If I edit the Text Property of an ASP:LABEL it immediately updates the

IDE's
> view.
>
> But when I make a control, and a designer for it, give it a Text
> Property...it doesn't.
> The only way I can get it to update is to switch to HTML view, add a space
> or tab to the file to ensure a DateTime change, save, and then return to

the
> page. Now it is updated.
>
> Direction one:
> I've looked at adding Attributes. That didn't seem to do it. Maybe I am
> using the wrong ones but ...?
>
> Direction two:
> I've not found good documentation as to what CreateChildControls() is used
> for, and when to override it without mucking up the ViewState, but I also
> tried this approach:
>
> public string Text {get {return _Text;}set {_Text
> =value;CreatedChildControls = false;}
>
> public override CreateChildControls(){
> this.Controls.Clear();
> HtmlGenericControl oSpan = new HtmlGenericControl("SPAN");
> oSpan.InnerHtml = _Text;
> this.Controls.Add(oSpan);
> }
>
> and see if that triggers it...nope as far as I can see. Plus, I'm not sure
> when in the lifespan of a control it is called. although it is somewhere.

Is
> it before ViewState is unpacked? After? What are the rules to watch out

for?
> Should I be creating my child elements here, or use my own protected
> _CreateElements() called from either Page_Load(), or override Render(),
> depending on whether I am trying to track clicks etc?
>
>
> I'm using VS2002 btw in case that means something -- but I don't think

this
> should be an issue (as the ASP:LABEL works correctly).
>
> As for the designer, I don't know if that it the problem. But in just in
> case, the Designer part looks in essense like:
>
> public class XActControlDesigner : System.Web.UI.Design.ControlDesigner {
> protected WebControl oControl;
>
> public override void Initialize(IComponent qComponent) {
> if(qComponent is Control) {try {base.Initialize (qComponent);oControl

=
> (WebControl)qComponent;}catch {}
> }
>
> public override string GetDesignTimeHtml() {
>
>
> try {
> oControl.BorderStyle = System.Web.UI.WebControls.BorderStyle.Dashed;
> oControl.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
> oControl.BorderColor =
> System.Drawing.ColorTranslator.FromHtml("#C0C0FF") ;
> return base.GetDesignTimeHtml();
> }
> catch(Exception E) {return GetErrorDesignTimeHtml(E);}
> }
>
> protected override string GetEmptyDesignTimeHtml(){
> return string.Format("<div style='border:dashed 1px blue;'>No HTML to
> render at this time.</div>");
> }
>
> protected override string GetErrorDesignTimeHtml(System.Exception E){
> string tControlName = "[N/A]"; try {tControlName =
> oControl.GetType().ToString();}catch {}
> string tStackTrace =

E.StackTrace.Replace(Environment.NewLine,"<br/>");
> return string.Format("<div style='border:double 3px
> red;font-family:Verdana,Tahoma, Arial;'><h4
> style='margin:0;padding:0;'>Error</h4><br/>Could not Render Control
> ({0})<hr/><div style=\"font-size:8pt;font-family:'Courier New'\"><h5
> style='margin:0;padding:0;'>Stack Trace
> {1}</h5>{2}</div></div>",tControlName,tInitMsg,tStackTrace);
> }
>
>
>
> Anybody have ideas for what to do?
>
> Thanks very very much.
>
> PS: I do have one more question. The idea does not seem to process STYLE
> tags, so if the Render() part ejects inline STYLE rules, it doesn't render
> them. It only renders colors, etc. if the css is inline. ... But in the

case
> of making a RichEdit control, that has lots of buttons, this seems to be a
> waste of bandwidth using "width:16px;height:16px;" etc. for every single
> button when class=ICON was nice and sweet. Any ideas on how to get the IDE
> to look like it will be in the final browser, exactly?
>
> Thanks so much.
> Sky
>
>



 
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
Custom webcontrol that references another webcontrol Fabricio ASP .Net Building Controls 0 09-21-2005 02:55 AM
Trapping an Exception ocurring in a Webcontrol at the Page or parent WebControl level. ASP .Net 2 01-31-2005 06:34 PM
WebControl inside of WebControl and attaching events Kasabaarde Sumta ASP .Net Building Controls 0 12-13-2004 09:51 PM
WebControl with non-WebControl property Peter Morris [Air Software Ltd] ASP .Net Web Controls 1 12-07-2004 12:25 PM
Can a webcontrol (webcontrol.dll) have a configuration file? Luis Ramírez. ASP .Net Building Controls 2 07-06-2004 04:35 PM



Advertisments