R
Rohan Parkes
I'm fairly new to ASP.NET, and am trying out the Online Newsletter
Manager project in Wrox's Beginning C#. The pages are supposed to bind
various controls (dropdown lists, datagrids) when the pages load,
through code in the Page_Load event.
However, it never works the first time the page loads. As far as I can
see, the Page_Load event doesn't fire, and if I set a break point, the
compiler says it won't be hit. It does work, however, when I click any
of the controls that fire isPostBack.
I haven't had this problem with other ASP.NET applications. The only
difference I can see is that all of the pages inherit from a base class
that just contains some utility functions.
I've reproduced some of the code below. I've seen similar code in some
of the ASP.NET examples in the SDK. I'm using the 1.0 framework.
I'd be grateful for any help.
--
Rohan Parkes
Melbourne
Australia
namespace NewsMailer
{
public class Lists : NewsMailer.BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// bind the page's controls
BindGrid();
}
}
protected void BindGrid()
{
NewsMailer.ListsDB lists = new NewsMailer.ListsDB
(GetConnString());
// get all the lists
DataView myDV = lists.GetLists().Tables
[0].DefaultView;
// sort the data according to the SortExpression
value
if ( ListsGrid.Attributes["SortExpression"] != null
)
myDV.Sort = ListsGrid.Attributes
["SortExpression"];
ListsGrid.DataSource = myDV;
ListsGrid.DataBind();
}
Manager project in Wrox's Beginning C#. The pages are supposed to bind
various controls (dropdown lists, datagrids) when the pages load,
through code in the Page_Load event.
However, it never works the first time the page loads. As far as I can
see, the Page_Load event doesn't fire, and if I set a break point, the
compiler says it won't be hit. It does work, however, when I click any
of the controls that fire isPostBack.
I haven't had this problem with other ASP.NET applications. The only
difference I can see is that all of the pages inherit from a base class
that just contains some utility functions.
I've reproduced some of the code below. I've seen similar code in some
of the ASP.NET examples in the SDK. I'm using the 1.0 framework.
I'd be grateful for any help.
--
Rohan Parkes
Melbourne
Australia
namespace NewsMailer
{
public class Lists : NewsMailer.BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// bind the page's controls
BindGrid();
}
}
protected void BindGrid()
{
NewsMailer.ListsDB lists = new NewsMailer.ListsDB
(GetConnString());
// get all the lists
DataView myDV = lists.GetLists().Tables
[0].DefaultView;
// sort the data according to the SortExpression
value
if ( ListsGrid.Attributes["SortExpression"] != null
)
myDV.Sort = ListsGrid.Attributes
["SortExpression"];
ListsGrid.DataSource = myDV;
ListsGrid.DataBind();
}