Click to See Complete Forum and Search --> : Dynamic generate web form in ASP.NET


yolip
May 21st, 2007, 08:18 AM
Hi all,

I am building a asp.net (vb.net) web application, however, i found it so hard to build friendly interface. In ASP, i can just generate a form and write it to the screen easily, then retrieve the value by using request.form or request.querystring etc, but ASP.NET, I did not same thing but doesn't works. for example: i use the code below, it did generate the table with controls and displayed in the page, but i can't find any way to get the value from generated control. e.g a value from a textbox called "txtquestion". Anyone know the way to do it? or I have to change to the other way? Please teach me how?

Thanks

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


Dim strOutput As New StringBuilder
strOutput.Append("<table id style=""width: 450px"">")
strOutput.Append(SampleFunc(datatable))
strOutput.Append("</table>")
Response.Write(strOutput)
End Sub

Public Function SampleFunc(ByVal Ds As DataTable) As String
'typeid = 1
Dim strResult As New StringBuilder
Dim iCount As Integer

strResult.Append("<tr>")

strResult.Append("<td colspan=""3"" style=""width: 450px"">")
strResult.Append(Ds.Rows(0)("Question"))
strResult.Append("</td>")
strResult.Append("</tr>")


strResult.Append("<tr>")
strResult.Append("<td colspan=""3"" style=""width: 450px; height: 7px"">")
For iCount = 0 To Ds.Rows.Count - 1
strResult.Append(Ds.Rows(iCount)("AnswerNum") & ")")
'strResult.Append("<asp:TextBox ID=" & Ds.Rows(iCount)("Question_ID") & "_" & Ds.Rows(iCount)("AnswerNum") & " runat=""server""></asp:TextBox><br />")
strResult.Append("<input ID=" & Ds.Rows(iCount)("Question_ID") & "_" & Ds.Rows(iCount)("AnswerNum") & " type=""text"" /><br />")
'<input id="Text1" type="text" />
Next

strResult.Append("</td>")
strResult.Append("</tr>")
strResult.Append("<tr>")
strResult.Append("<td colspan=""3"" style=""width: 450px; height: 5px"">")
strResult.Append("</td>")
strResult.Append("</tr>")

Return strResult.ToString


End Function

Shuja Ali
May 21st, 2007, 08:36 AM
Basically it is easier than in Classic ASP. You are actually looking for Dyanmic Controls. Take a look at this
http://aspnet.4guysfromrolla.com/articles/081402-1.aspx

You can also utilize something known as User Controls in ASP.NET.

yolip
May 21st, 2007, 08:45 AM
thanks for your reply. I will get into basic when i have more time. But can you just tell me is it possible to do what i described in the question? Actually i found all the ASP.net samples on the internet are ugly. any site that can show me how to build a pretty web site using asp.net?

mcmcom
May 21st, 2007, 08:53 PM
how "pretty" your site is is not up to asp.net its up to the designer and developer. There is no place that can teach you to build a pretty site. A pretty good designer can be a help though.

hth,
mcm

yolip
May 21st, 2007, 09:23 PM
well, as i found the tutorials from the web, they all teaching you with a simple form, e.g. login form, simple search (one text box + one button), or something similar like that. I still don't see any where telling you how to format your form better. Wherever i post that kind of question, people just avoid or post the answer like yours. I don't know what's that mean. If i am a good programmer, then i should helping people, not asking question here. If you think my question is stupid, then please don't have to answer it.

Shuja Ali
May 22nd, 2007, 02:40 AM
The reason why you get almost same answers should be obvious to you now. Being a good programmer doesn't mean that one will be a good designer too. Actually programming has got nothing to do with the web page design. There are so many companies who hire designers (who just know HTML/Flash/JavaScript and other design tools) to design their web pages and programmers are given the responsibility of just coding (after all thats what programmers are for).

I don't think there will be any web sites that will teach you how to design a web site. As suggested earlier, try looking for a designer with whom you can talk.

mcmcom
May 22nd, 2007, 12:05 PM
I agree, but to be a bit more helpful than i was in the last post... if you are set on learning some good techniques and standards the best place to look is the W3C Consortium who manages all web standards. (www.w3c.org)

also CSS is what most people use to stylize their sites (layout, fonts, formatting)
good place to start learning CSS is here : http://www.w3schools.com/css/

and the w3 schools site is good for all kinds of html, css stuff

http://www.w3schools.com

hth,
mcm