ASP Composite Web Control and Position

  • Thread starter Thread starter Craig Glencross
  • Start date Start date
C

Craig Glencross

I have created a Composite Control in C# 2005 for ASP. It has 3 buttons, a
calendar control and some drop down lists.

It compiles correctly and I can use it on a test web site but I cannot
control where to place it on the web page.

I have tried positioning tags such as relative or absoulte. Can you explain
what I am missing? Do I have to expose the style property? Her e is the
Render function:


//-------------------------------------------------------------------------------
// Place the child controls in the correct positions on this control

//-------------------------------------------------------------------------------
public override void RenderControl(HtmlTextWriter writer)
{

writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
txtCalendar.RenderControl(writer);
btnCalendar.RenderControl(writer);
writer.RenderEndTag(); // td
writer.RenderEndTag(); // tr

writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
calMain.RenderControl(writer);
writer.RenderEndTag(); // td
writer.RenderEndTag(); // tr

writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
ddlHours.RenderControl(writer);
ddlMinutesMajor.RenderControl(writer);
ddlMinutesMinor.RenderControl(writer);
ddlAMorPM.RenderControl(writer);
writer.RenderEndTag(); // td
writer.RenderEndTag(); // tr

writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
btnUpdate.RenderControl(writer);
btnCancel.RenderControl(writer);
writer.RenderEndTag(); // td
writer.RenderEndTag(); // tr


writer.RenderEndTag(); // table
}



Thanks.
 
your parent control (the table) does not render any of the position
attributes (style) that may be specified by the designer or page source. you
should render any style attributes and the cssclass if specified.

-- bruce (sqlwork.com)
 
I am new to this. Can you please explain how to do the render of the
position attributes?

Thanks in advance.
 
Hi there,

// tag attributes must be added before the corresponding tag

writer.AddStyleAttribute(HtmlTextWriterStyle.Position, "absolute");
writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
//.. etc

Hope this helps
 
Back
Top