Last post Feb 12, 2008 10:26 PM by KosMos
Feb 12, 2008 07:42 PM|KosMos|LINK
hello I am rather new to asp programming and am having a problem with rending a custom control for web app that I am building. I am using an html textwriter to write to write a seeries of lines that includes a checkbox that will be evaluated at the server
for which line is selected. I have been able to get the lines to print however the checkbox for some reasaon will not render. I was wondering if I will have to put a Checkbox list on the page and write the html within the texbox list so that the server will
render the checkbox's on the page.
Dim amstr As String = amshifts.InnerHtml
Dim writer As New StringWriter
Dim pgwriter As HtmlTextWriter
pgwriter = New HtmlTextWriter(writer)
Dim amout As String = writer.ToString()
Dim concat As Integer = amout.IndexOf("Sys")
amout = amout.Remove(concat, 28)
amshifts.InnerHtml = amstr & amout
Catch ex As Exception
If Not pgwriter Is Nothing Then
Feb 12, 2008 09:57 PM|jose_jimenez|LINK
A server side checkbox has to be rendered onto the page as html. What your code is doing is emitting the literal "<checkbox id=" and so on which is not valid html. A valid checkbox when rendered as html would be "<input type='checkbox' ..." and so on.
There are a couple of things you could do to have the effect you are looking for. One option is to create a custom control as a composite control. Use the design time features to add a checkbox to your custom control. Add whatever text you want to the
ascx file to go around the textbox including your div text for example. If you do that, you won't have to create a custom render method. It will just emit the correct html. Another option is to create a checkbox object in your code around line 12. Set
any properties you like and then render it to the same outputstream
Dim cb as CheckBox
cb.Id = chkbxid
Feb 12, 2008 10:26 PM|KosMos|LINK
Thankyou for pointing out my gross mistake of html rendering!
Initialy I Had set the html textwriter to render an asp:checkbox as
Doing it this way though the server would render the wh0le line in the page and could be seen in the page source but the page would not render the server control for some reason but could see everything else. However you reminded me that that any tag can be turned into a server control by adding the runat server attribute to the tag. Also I apologize for not adding that the writer would write the control line from a xml file so a custom control was needed to output the data to the line.
However if I change a coupel of lines to