fvincentis Posted June 6, 2006 Share Posted June 6, 2006 Hi guys,I just had a first look at ASP.NET and I quite like the way it works. However, I am a bit annoyed by the HTML that the Web Controls create automatically for me.An example:<form runat="server"><asp:RadioButtonList id="countrylist" runat="server" class="andreas"><asp:ListItem value="N" text="Norway" /><asp:ListItem value="S" text="Sweden" /></asp:RadioButtonList></form>The code above creates a lot of HTML that in my opinion is unnecessary. The result source code looks something like this:<form name="_ctl0" method="post" action="index.aspx" id="_ctl0"><input type="hidden" name="__VIEWSTATE" value="dDwtMTk3NTMzNTYxMDs7PhRKws7MrkiprJLJqu4rbrdBhNoQ" /><table id="countrylist" class="andreas" border="0"><tr><td><input id="countrylist_0" type="radio" name="countrylist" value="N" /><label for="countrylist_0">Norway</label></td></tr><tr><td><input id="countrylist_1" type="radio" name="countrylist" value="S" /><label for="countrylist_1">Sweden</label></td></tr></table></form>I would liv to get rid of the table that is being created automatically. All I want is the label and the input for each radio button. The rest I want to do with CSS myself.So I was wondering if there is any way to change the HTML that is being created? Can I prevent .NET from creating unnecessary tables like the one above?Thanks for the help. Link to comment Share on other sites More sharing options...
aspnetguy Posted June 6, 2006 Share Posted June 6, 2006 You don't have to use the ASP.Net Controls you can use the standard HTML controls...there is usually very little difference in features.eg <asp:TextBox id="txtMyBox" runat="server"/> is essentially the same as do this <input type="text" id="txtMyBox" runat="server"/> Link to comment Share on other sites More sharing options...
fvincentis Posted June 7, 2006 Author Share Posted June 7, 2006 You don't have to use the ASP.Net Controls you can use the standard HTML controls...there is usually very little difference in features.Ah, good to know. I just gave it a go, but it seems if I use the HTML controls instead of the .NET controls, I cannot directly modify the properties of the elements anymore. Let's take the next code as an example:<script runat="server">Sub submit(sender As Object, e As EventArgs)lbl1.Text="Your name is " & txt1.TextEnd Sub</script><html><body><form runat="server">Enter your name:<asp:TextBox id="txt1" runat="server" /><asp:Button OnClick="submit" Text="Submit" runat="server" /><p><asp:Label id="lbl1" runat="server" /></p></form></body></html> The above script prints out a label after I enter content into the textbox. This is what I really like so far about ASP.NET, but it doesn't work with the following code: <script runat="server">Sub submit(sender As Object, e As EventArgs)lbl1.Text="Your name is " & txt1.TextEnd Sub</script><html><body><form runat="server">Enter your name:<input type="text" id="txt1" runat="server"/><asp:Button OnClick="submit" Text="Submit" runat="server" /><p><asp:Label id="lbl1" runat="server" /></p></form></body></html> Sooo... I guess this means if I use HTML controls I cannot talk to the control attributes as I would be able to do if they were .NET controls, right? Doesn't that defeat the advantage of .NET over other languages? Sorry, as you can take I am really new to this language - I am still trying to understand what the advantage of .NET is over PHP or regular ASP. Link to comment Share on other sites More sharing options...
aspnetguy Posted June 7, 2006 Share Posted June 7, 2006 change this line lbl1.Text="Your name is " & txt1.Text to lbl1.Text="Your name is " & txt1.Value The syntax may vary a little but the features are pretty much the same. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now