p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 (http://p2p.wrox.com/forumdisplay.php?f=389)
-   -   Chapter 4: Page 391 - ButtonType (http://p2p.wrox.com/showthread.php?t=67488)

VeganMan April 17th, 2008 10:46 AM

Chapter 4: Page 391 - ButtonType
 
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




dparsons April 17th, 2008 11:07 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
================================================== =========

Imar April 17th, 2008 11:26 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.

VeganMan April 17th, 2008 11:45 AM

That's great, thanks guys...

Terry


dparsons April 17th, 2008 11:45 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
================================================== =========

VeganMan April 19th, 2008 05:12 AM

Quote:

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


Imar April 19th, 2008 06:57 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.

VeganMan April 19th, 2008 08:42 PM

Quote:

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

Imar April 20th, 2008 04:35 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.


All times are GMT -4. The time now is 10:44 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.