|

January 10th, 2009, 09:50 AM
|
|
Authorized User
|
|
Join Date: Dec 2008
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
chapter10
Hi,
Sorry for disturbing again. Now some problem with Chapter 10, Using the New control
TIO(page 375).
Ther first point suggested that- "Open Visual Developer and select Open website
.From the Chapter10 folder (C:\BegASPNET2\Chapters\Begin\Chapter10),Select WroxUnitedNewsControl and
click OK." Now the problem is that in Chapter10 there is no folder named as WroxUnitedNewsControl.
Chapter 10 folder contains NewsUserControl,ObjectDataSource,SimpleUserControl ,TestCodeBehind and WroxUnited folders only.
So I have tried that TIO in NewsUserControl folder.
But when I run the NewsDisplay.aspx , it is not showing anything rather than a blank page.
The codes are as follows:
NewsUserControl.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="NewsUserControl.ascx.cs" Inherits="NewsUserControl" %>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:WroxUnited %>" ></asp:SqlDataSource>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<div class="newsItem">
<span class="newsDate"><%#Eval("DateToShow","{0:dd MM yyyy}") %></span>
<span class="newsTitle"><%#Eval("Title") %></span>
</div>
<span class="newsContent"><%#Eval("Description") %></span>
</ItemTemplate>
</asp:Repeater>
NewsUserControl.ascx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class NewsUserControl : System.Web.UI.UserControl
{
private int _itemsToShow = 5;
public int ItemsToShow
{
get
{
return _itemsToShow;
}
set
{
_itemsToShow = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Repeater1_PreRender(object sender, EventArgs e)
{
string sel = string.Format("SELECT Top {0} * FROM [News] WHERE DateToShow <= '{1}' ORDER BY DateToShow DESC", _itemsToShow, DateTime.Now.ToString("yyyy/MM/dd"));
//Make sure above is all on one line.
SqlDataSource1.SelectCommand = sel;
}
}
NewsDisplay.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewsDisplay.aspx.cs" Inherits="NewsDisplay" %>
<%@ Register Src="NewsUserControl.ascx" TagName="NewsUserControl" TagPrefix="uc1" %>
<!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 runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:NewsUserControl ID="NewsUserControl1" runat="server" />
</div>
</form>
</body>
</html>
NewsDisplay.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class NewsDisplay : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Default.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
web.config:
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<appSettings/>
<connectionStrings>
<add name="WroxUnitedConnectionString" connectionString="Data Source=LOCALHOST\SQLEXPRESS;AttachDbFilename=C:\Be gASPNET2\Chapters\Begin\Chapter10\NewsUserControl\ App_Data\WroxUnited.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="WroxUnited" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\WroxUnited.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true"/>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>
Thanks in advance.
Regards,
jackSparrow
|