Arnoldus The Multi Language Site in C#

Multi Language Site: Page Text (Part 1.2)



This is the continuation of Part 1.1 (Multi Language Site: Page Text)


Displaying Content

Let's look at a hypotetical page (Default2.aspx) that displays text retrieved from the database. The code for the page is quit simple:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>
            Sample Page
        </title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="shim solid">
            </div>
            <div id="solidwhite" class="pagecenter">
                <div style="text-align: center">
                    <br />
                    <asp:DataList ID="DataList1" runat="server"
                        DataSourceID="ObjectDataSource1">
                        <ItemTemplate>
                            <table id="Tab1" cellspacing="0" border="0"
                                   style="border-collapse: collapse;
                                   width: 984px">
                                <tr>
                                    <td style="text-align: center">
                                        <h3>
                                            <%# Eval("hdr1")%>
                                        </h3>
                                        <br />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: center">
                                        <br />
                                        <h4>
                                            <%# Eval("hdr2")%>
                                        </h4>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:DataList>
                    <div id="sidebar">
                    </div>
                    <br />
                    <div id="codecontent">
                        <asp:DataList ID="DataList3" runat="server"
                             DataSourceID="ObjectDataSource1">
                            <ItemTemplate>
                                <h4>
                                    <%# Eval("hdr3")%>
                                </h4>
                                <%# Eval("fld1")%>
                                <%# Eval("fld2")%>
                                <%# Eval("fld3")%>
                            </ItemTemplate>
                        </asp:DataList></div>
                </div>
            </div>
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
                SelectMethod="GetContents"
                TypeName="Contents">
                <SelectParameters>
                    <asp:Parameter DefaultValue="Default2.aspx"
                         Name="Page" Type="String" />
                </SelectParameters>
            </asp:ObjectDataSource>
        </form>
    </body>
</html>


Explanation:

The header code is the usual for an .aspx page. The content section (besides the formatting instructions) is characterized
by the use of Datalist blocks that display the contents (hdr1, hdr2, hdr3, fld1, fld2). The datalists refer to ObjectDataSource1, which is responsible for retrieving the contents for Default2.aspx.

From the code sofar, there is no indication that content will vary according to the language settings of the browser (or the language selected by the user). This we will address in parts 1.3. and 1.4

Continue to: Multi Language Site: Page Text (Part 1.3): Contents Class.