problems with AutoPostBack

  • Thread starter Thread starter Sean Chapman
  • Start date Start date
S

Sean Chapman

I've got a simple page I've made with a few controls (Treeview,
Dropdownlist, ..). I'm running into an issue with autopostback. If I
set it to AutoPostBack = "True", when the event should fire I get a
Javascript error in IE.

*Note: this is using Visual Studio 2005 std. and .NET 2.0*

If I don't set it, and let a button click do the postback, the event
fires normally.

Any help would be greatly appreciated.

IE Error:
Line: 34
Char: 9
Error: Object doesn't support this property or method.
Code: 0
URL: http://localhost:4022/ReportScheduler/ManageReports.aspx

markup:
<form id="form1" runat="server">
<asp:Table runat=server ID="contentTable" >
<asp:TableRow>
<asp:TableCell VerticalAlign="Top">
<asp:TreeView runat=server ID="reportListing"
OnSelectedNodeChanged="reportListing_SelectedNodeChanged">
</asp:TreeView>
</asp:TableCell>
<asp:TableCell VerticalAlign="Top">
<asp:GridView runat=server ID="reportDetails">

</asp:GridView>
</asp:TableCell>
<asp:TableCell VerticalAlign="Top">
<asp:DropDownList runat="server"
ID="frequencyListDropDown" AutoPostBack="true"
OnSelectedIndexChanged="frequencyListDropDown_SelectedIndexChanged">
<asp:ListItem
Selected=True>Daily</asp:ListItem>
<asp:ListItem>Weekly</asp:ListItem>
<asp:ListItem>Middle And End Of
Month</asp:ListItem>
<asp:ListItem>Monthly</asp:ListItem>
</asp:DropDownlist>
</asp:TableCell>
<asp:TableCell VerticalAlign="Top">
<asp:CheckBoxList runat=server ID="daysOfWeek"
RepeatDirection="Horizontal" Visible=false>
<asp:ListItem>Sunday</asp:ListItem>
<asp:ListItem>Monday</asp:ListItem>
<asp:ListItem>Tuesday</asp:ListItem>
<asp:ListItem>Wednesday</asp:ListItem>
<asp:ListItem>Thursday</asp:ListItem>
<asp:ListItem>Friday</asp:ListItem>
<asp:ListItem>Saturday</asp:ListItem>
</asp:CheckBoxList>
<asp:Calendar runat=server ID="monthDaySelect"
Visible=false></asp:Calendar>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
<asp:TableCell>
<asp:Button runat=server ID="submit"
OnClick="submit_click" Text="Submit" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>

Codebehind:

public partial class ManageReports : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack) //set up initial page
{

System.Data.DataSet reportList = new DataSet();
reportList.ReadXml(Server.MapPath("Reports.xml"));
foreach (DataTable t in reportList.Tables)
{
foreach (DataRow dr in t.Rows)
{
TreeNode parentNode = new TreeNode();
parentNode.Text = dr.Table.TableName;
reportListing.Nodes.Add(parentNode);
foreach (string innerRow in dr.ItemArray)
{
parentNode.ChildNodes.Add(new
TreeNode(innerRow));
}
}
}
}
}

protected void frequencyListDropDown_SelectedIndexChanged(object
sender, EventArgs e)
{
//if (IsPostBack)
{
if (frequencyListDropDown.SelectedValue == "Monthly")
{
daysOfWeek.Visible = false;
monthDaySelect.Visible = true;

}
else if (frequencyListDropDown.SelectedValue == "Weekly")
{
daysOfWeek.Visible = true;
monthDaySelect.Visible = false;
}
else if ((frequencyListDropDown.SelectedValue == "Daily")
|| (frequencyListDropDown.SelectedValue == "Middle And End Of Month"))
{
daysOfWeek.Visible = false;
monthDaySelect.Visible = false;
}
}
}

protected void submit_click(object sender, EventArgs e)
{

}

protected void reportListing_SelectedNodeChanged(object sender,
EventArgs e)
{

}
 
That was most of it.. but here's the full copy/past for the markup/code
behind:


MARKUP:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="ManageReports.aspx.cs" Inherits="ManageReports" %>

<!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>Manage Report Schedule</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Table runat=server ID="contentTable" >
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server"
ID="userLabel"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell VerticalAlign="Top">
<asp:TreeView runat=server ID="reportListing"
OnSelectedNodeChanged="reportListing_SelectedNodeChanged">
</asp:TreeView>
</asp:TableCell>
<asp:TableCell VerticalAlign="Top">

</asp:TableCell>
<asp:TableCell VerticalAlign="Top">
<asp:DropDownList runat="server"
ID="frequencyListDropDown" AutoPostBack="true"
OnSelectedIndexChanged="frequencyListDropDown_SelectedIndexChanged">
<asp:ListItem
Selected=True>Daily</asp:ListItem>
<asp:ListItem>Weekly</asp:ListItem>
<asp:ListItem>Middle And End Of
Month</asp:ListItem>
<asp:ListItem>Monthly</asp:ListItem>
</asp:DropDownlist>
</asp:TableCell>
<asp:TableCell VerticalAlign="Top">
<asp:CheckBoxList runat=server ID="daysOfWeek"
RepeatDirection="Horizontal" Visible=false>
<asp:ListItem>Sunday</asp:ListItem>
<asp:ListItem>Monday</asp:ListItem>
<asp:ListItem>Tuesday</asp:ListItem>
<asp:ListItem>Wednesday</asp:ListItem>
<asp:ListItem>Thursday</asp:ListItem>
<asp:ListItem>Friday</asp:ListItem>
<asp:ListItem>Saturday</asp:ListItem>
</asp:CheckBoxList>
<asp:Calendar runat=server ID="monthDaySelect"
Visible=false></asp:Calendar>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
<asp:TableCell>
<asp:Button runat=server ID="submit"
OnClick="submit_click" Text="Submit" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</html>





CODEBEHIND:

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;
using System.Xml;

public partial class ManageReports : System.Web.UI.Page
{


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) //set up initial page
{
System.Data.DataSet reportList = new DataSet();
reportList.ReadXml(Server.MapPath("Reports.xml"));
userLabel.Text = (string)Session["user"];
foreach (DataTable t in reportList.Tables)
{
foreach (DataRow dr in t.Rows)
{
TreeNode parentNode = new TreeNode();
parentNode.Text = dr.Table.TableName;
reportListing.Nodes.Add(parentNode);
foreach (string innerRow in dr.ItemArray)
{
parentNode.ChildNodes.Add(new
TreeNode(innerRow));
}
}
}
}
}

protected void frequencyListDropDown_SelectedIndexChanged(object
sender, EventArgs e)
{
//if (IsPostBack)
{
if (frequencyListDropDown.SelectedValue == "Monthly")
{
daysOfWeek.Visible = false;
monthDaySelect.Visible = true;

}
else if (frequencyListDropDown.SelectedValue == "Weekly")
{
daysOfWeek.Visible = true;
monthDaySelect.Visible = false;
}
else if ((frequencyListDropDown.SelectedValue == "Daily")
|| (frequencyListDropDown.SelectedValue == "Middle And End Of Month"))
{
daysOfWeek.Visible = false;
monthDaySelect.Visible = false;
}
}
}

protected void submit_click(object sender, EventArgs e)
{

}

protected void reportListing_SelectedNodeChanged(object sender,
EventArgs e)
{

}


}



thanks for any input.
 
Back
Top