Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 17th, 2008, 10:46 AM
Authorized User
 
Join Date: Jan 2007
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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



 
Old April 17th, 2008, 11:07 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
================================================== =========
 
Old April 17th, 2008, 11:26 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old April 17th, 2008, 11:45 AM
Authorized User
 
Join Date: Jan 2007
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's great, thanks guys...

Terry

 
Old April 17th, 2008, 11:45 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

<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
================================================== =========
 
Old April 19th, 2008, 05:12 AM
Authorized User
 
Join Date: Jan 2007
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old April 19th, 2008, 06:57 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old April 19th, 2008, 08:42 PM
Authorized User
 
Join Date: Jan 2007
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old April 20th, 2008, 04:35 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 9 Page 304 AspNetGuy BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 12 December 22nd, 2009 11:17 AM
Problem with Chapter 2 First Page xtiano77 ASP.NET 3.5 Basics 1 May 7th, 2008 01:00 AM
Chapter 3 - Page.IsCrossPagePostBack dpereira BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 9 October 25th, 2006 07:50 AM





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