Saturday, March 31, 2012

Server Side FieldSet?

I'm trying to write a Web Custom control that allows me to generate a set of server side text boxes inside the fieldset element. What I have is this:

protectedoverridevoid Render(HtmlTextWriter output)

{

StringBuilder sb =new StringBuilder();

//Begin the FieldSet if it's needed

if (this.ShowBorder )

sb.Append(string.Format("<fieldset style='WIDTH: {0}; HEIGHT: {1}'><legend>{2}</legend>",this.Width,this.Height,this.Legend));

//Add user controls

for(int i = 0; i <this.SearchFormFields.Length; i++)

{

SearchField curField =this.SearchFormFields[i];sb.Append(string.Format("<span class='fwifont'>{0}</span><br>", curField.Title));

//sb.Append(string.Format("<FWI:MultiRangeTextBox CssClass='fwifont' id=AccountNumberBox runat='server' TermName='{0}'></FWI:MultiRangeTextBox>", curField.TermName));

sb.Append("<asp:TextBox Runat='server' ID='fsdfd'></asp:TextBox>");

}

sb.Append("<br>");

//Finish off fieldset

if (this.ShowBorder )

sb.Append("</fieldset>");

sb.Append("<br>");

output.Write(sb.ToString());

}

However, the asp:text box does not render or show up. I'm guessing this has something to do with the fact that it's a server side control itself. Does anyone have any ideas on what I'm doing wrong here?

You are trying to output ASP control tags as markup. Would something like "<input type="text" id=......" rather the the ASP textbox control be more suitable?

Ta


Most unfortuantely, no, I cannot use html input fields. And actually, it not only needs to be a server side control, in reality it should be a custom web control that actually extends the asp:textbox class. I have a method that traverses all the controls on the web forms and handles the input of each textbox based on what "type" of server side text box it is.

0 comments:

Post a Comment