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

S

Sky

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
 
S

Sky

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 said:
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 =
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top