Subject: Wrox Photo Album Help
Posted By: rsearing Post Date: 9/26/2006 8:44:58 PM
Ok, I'm quite the beginner here and most of the Wrox books I've purchased are step by steps that don't combine alot into an application such as in this book.

I am having a difficult time on understanding how to mix classes in (why you would) when you have sqldatasource's that can tie direct to databases--or have datasets, so I am trying to start with the Photo Album project and piece part it.

The first page aspx page (pg 223) is the photos.aspx page.  What purpose does having "class=photoname" or "class=collection" in the <a> tag and <table align> tag?  Are these classes?  Why am I putting them here.

Kind Regards,
Rob

Reply By: Imar Reply Date: 9/27/2006 1:58:14 AM
Yes, they are classes, but not .NET classes like Product or Album.

They are CSS classes, are used to influence the presentation of a web page and refer to styles defined either inline or in a CSS file.

E.g.

<a href="#" class="MyLink">Click Me</a>

<style type="text/css">

.MyLink
{
  color: green;
}

</style>

In this case, the CSS class MyLink causes the link to become blue.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply By: rsearing Reply Date: 9/27/2006 7:52:11 AM
Makes sense---I'm just confused why there is other specific references in different syntax such as "CssClass=something" (Sorry at work and don't have the book).

So, in other words, there is "class= XXX" and "CssClass= XXX"??

THanks so much,
Rob

Reply By: Imar Reply Date: 9/27/2006 8:18:31 AM
CssClass is an ASP.NET server side control property that maps to the client side HTML class attribute.

So:

<asp:Image CssClass="SomeClass" ImageUrl="SomeImage.gif" runat="Server" />

ends up as :

<img src="SomeImage.gif" class="SomeClass" />

in the browser.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply By: rsearing Reply Date: 9/27/2006 8:57:53 AM
Ok...last question...I had my wife email me the source...so, am I correct in stating that the reason you have two different syntaxes (within one ASP Datalist control) is because the cssClass="item" references the ASP.Net control..however, the class="photoname" references an "a" tag (HTML).  What threw me is you saying that class would reference html client code (rendered on page) and cssClass was for the control--however you see both used in the server code below.  I assume for the reason I mentioned above?


Thank you,
Rob

<asp:DataList ID="DataList1" runat="Server"  dataSourceID="SqlDataSource1"
    repeatColumns="6"  repeatdirection="Horizontal" borderwidth="0px" cellpadding="3">
    <ItemStyle cssClass="item" />
    <ItemTemplate>          
    <table align=left border="0" cellpadding="0" cellspacing="0">
         <tr>
            <td></td>
            <td nowrap width="100" valign="top">
            <a class="photoname" href="viewphoto.aspx?photoID=<%# Eval("photoID") %>">
            <%#GetName(Server.HtmlEncode(Eval("Name").ToString()))%>
            </a>
            </td>
            <td></td>                        
        </tr>      
        <tr>
            <td></td>
            <td>
                <a href='viewphoto.aspx?photoID=<%# Eval("photoID") %>' >
                    <img class="viewphoto" src="upload/<%# Eval("filepath") %>"
                    height="95" width="95" alt='<%# Eval("description") %>' />
                </a>
            </td>
            <td></td>
        </tr>
    </table>
    </ItemTemplate>
</asp:DataList>

Reply By: Imar Reply Date: 9/27/2006 12:55:39 PM
The DataList control you posted is a mix of server side and client side code. Or to be more exact: the server side DataList control contains an ItemTemplate that will be repeated for each item in your data source. This ItemTemplate in turn contains HTML that is send to the browser as is. That is, it's not transformed in any way.

That is why you see CssClass on the DataList (a server control that runs at the server and emits HTML to client, including a transformation from the CssClass property to the class attribute) and just class on the <a> and other tags in the ItemTemplate.

Just for fun, right-click one of those pages in the browser and choose View Source. You'll see that the DataList has been transformed to client side code (a <table> I think) and that the CssClass properties have been changed to class attributes.

Hope this clarifies things.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply By: rsearing Reply Date: 9/27/2006 2:30:20 PM
Wonderful--thank you for your help!

Kind Regards,
Rob


Go to topic 50230

Return to index page 452
Return to index page 451
Return to index page 450
Return to index page 449
Return to index page 448
Return to index page 447
Return to index page 446
Return to index page 445
Return to index page 444
Return to index page 443