|
Subject:
|
Chapter 4: Page 391 - ButtonType
|
|
Posted By:
|
VeganMan
|
Post Date:
|
4/17/2008 10:46:16 AM
|
Hi Imar,
You mentioned said could generate a button using the following code:
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" ButtonType="Button"> </asp:CommandField>
I've noticed that others have used the code below. It seems easier to use. Could the code below create a problem?
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" ButtonType="Button" /> Thank you, Terry
|
|
Reply By:
|
dparsons
|
Reply Date:
|
4/17/2008 11:07:40 AM
|
The only difference between the two examples that you have presented is that the latter is a self closing tag (hence the /> at the end instead of </asp:CommandField>). Either example will work fine without a problem.
On thing to keep in mind is that you can use this short hand to close all of your Server Control tags (Label, button, textbox, etc) however, you can't use this short hand on a dropdownlist, for example, when you explictly define the items displayed in the list:
<asp:DropDownList ID="drp" runat="server"> <asp:ListItem>foo</asp:ListItem> </asp:DropDownList>
hth.
-Doug
=========================================================== Read this if you want to know how to get a correct reply for your question: http://www.catb.org/~esr/faqs/smart-questions.html =========================================================== .: Wrox Technical Editor / Author :. Wrox Books 24 x 7 ===========================================================
|
|
Reply By:
|
Imar
|
Reply Date:
|
4/17/2008 11:26:17 AM
|
Or:
<asp:DropDownList ID="drp" runat="server"> <asp:ListItem Text="foo" Value="foo" /> </asp:DropDownList>
;-)
But Doug is right; there's no difference. I usually use /> but sometimes I forget an element is self closing and accidentally type >. Then VWD inserts the end tag automatically which I usually leave in there.
Feel free to choose whatever you are most comfortable with.
Also, check out Tool | Options | Text Editor | HTML | Format.
Then click the Tag Specific Options button. In the dialog that follows, you can control the way tags are entered in the designer, including whether they auto close or not.
Cheers,
Imar
--------------------------------------- Imar Spaanjaars http://Imar.Spaanjaars.Com Everyone is unique, except for me. Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004 Want to be my colleague? Then check out this post.
|
|
Reply By:
|
VeganMan
|
Reply Date:
|
4/17/2008 11:45:20 AM
|
That's great, thanks guys...
Terry
|
|
Reply By:
|
dparsons
|
Reply Date:
|
4/17/2008 11:45:31 AM
|
<asp:ListItem Text="foo" Value="foo" />
Yep that will work to! ;]
=========================================================== Read this if you want to know how to get a correct reply for your question: http://www.catb.org/~esr/faqs/smart-questions.html =========================================================== .: Wrox Technical Editor / Author :. Wrox Books 24 x 7 ===========================================================
|
|
Reply By:
|
VeganMan
|
Reply Date:
|
4/19/2008 5:12:13 AM
|
quote: Originally posted by Imar
Or:
<asp:DropDownList ID="drp" runat="server"> <asp:ListItem Text="foo" Value="foo" /> </asp:DropDownList> ...
Oh, sort of like the code automatically generated on page 400:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Id" AppendDataBoundItems="True"> <asp:ListItem Value="">Please make a selection</asp:ListItem> </asp:DropDownList>
Which can be changed to:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Id" AppendDataBoundItems="True"> <asp:ListItem Value="" Text="Please make a selection" /> </asp:DropDownList>
If it's a better code, why isn't the program creating it that way?
Terry
|
|
Reply By:
|
Imar
|
Reply Date:
|
4/19/2008 6:57:27 AM
|
Who says it's better code? I just posted my code example to show another variation of self closed elements.
Both come down to the same thing; there is no difference at run-time so again you can choose whatever you see fit or like best.
Imar --------------------------------------- Imar Spaanjaars http://Imar.Spaanjaars.Com Everyone is unique, except for me. Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004 Want to be my colleague? Then check out this post.
|
|
Reply By:
|
VeganMan
|
Reply Date:
|
4/19/2008 8:42:20 PM
|
quote: Originally posted by Imar
Who says it's better code? I just posted my code example to show another variation of self closed elements.
Both come down to the same thing; there is no difference at run-time so again you can choose whatever you see fit or like best.
Imar
I'm saying it's a better code as it takes less bites. Yes they both work.
ALSO: I didn't even mention your code as I wasn't even thinking of your code. I said "... like the code automatically generated on page 400." I did the exercise on page 400 and the code was generated for me automatically.
My message was meant to show you that I not only understood you, but agreed with you. I was just delighted that I learned something (and learned a lot more than I shared here just because of the post I was referring to).
I apologize if I didn't word my post correctly. But be delighted that I learned something due to your original post that I was referring too, showing you that the forum is very helpful.
Thank you for it...
Terry
|
|
Reply By:
|
Imar
|
Reply Date:
|
4/20/2008 4:35:00 AM
|
Right I see.
Fortunately, VWD gives you full control over this so you can code it any way you want..... ;-)
Imar
--------------------------------------- Imar Spaanjaars http://Imar.Spaanjaars.Com Everyone is unique, except for me. Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004 Want to be my colleague? Then check out this post.
|