Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting up .NET website

Status
Not open for further replies.

mjd3000

Programmer
Apr 11, 2009
136
GB
When setting up a .NET website on a web server, is there any reason why the page could should, but the C# code doesn't seem to execute? Our network person has just set up a .NET site, and the page renders OK, but the dropdown that should be populated in the Page_Load event is not populated. After changing the Page_Load event by adding some test code to see whether the event runs at all, it does not seem to run. Any ideas why?
 
provide the code, otherwise we are just guessing.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
The problem is not the code, the code works fine locally, but even the Page_Load does not run on the web server.

protected void Page_Load(object sender, EventArgs e)
{

//label1.text = "Page load is running OK';


if (!IsPostBack)
{
DataAccess da = new DataAccess();

DataSet dsProgrammes = da.getProgrammes();

ddlProgrammes.Items.Clear();
ddlProgrammes.Items.Add(new ListItem("--Please select--", ""));

for (int i = 0; i < dsProgrammes.Tables[0].Rows.Count; i++)
{
ddlProgrammes.Items.Add(new ListItem(dsProgrammes.Tables[0].Rows
["new_programmemoidname"].ToString()));
}
}
}
 
this is your problem
Code:
ddlProgrammes.Items.Clear();
            ddlProgrammes.Items.Add(new ListItem("--Please select--", ""));
if you are not using the binding feature you will need to do this everytime.
I would recommend updating your code to this
Code:
if(IsPostBack) return;

ddlProgrammes.DataSource = new DataAccess().getProgrammes();
ddlProgrammes.DataBind();
ddlProgrammes.Items.Insert(0,new ListItem("--Please select--", ""));

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
But the thing is that the test line before the Postback block does not run, which makes me think that the event isn't running at all :

label1.text = "Page load is running OK';

 
hmmm... so maybe autowiring is not configured.

1st, make sure the autowiring is set to true. this would be located in the page directive at the top of the aspx file. it could also be defined in the web.config. The default to true. if it's set to false Page_Load and similar members will not be wired for you.

if this is the case you have 3 options.
1. turn autowiring on
Code:
WireEvents=true
or something like that.
2. wire the events explicitly
Code:
class MyPage : Page
{
   public MyPage()
   {
       Load += LoadDDL;
   }

   public override void Dispose()
   {
       Load -= LoadDDL;
   }

   private void LoadDDL(object sender, EventArgs e)
   {
      if(IsPostBack) return;

      ddlProgrammes.DataSource = new DataAccess().getProgrammes();
      ddlProgrammes.DataBind();
      ddlProgrammes.Items.Insert(0,new ListItem("--Please select--", ""));
   }
}
3. override the OnLoad handler
Code:
class MyPage : Page
{
   protected override void OnLoad(EventArgs e)
   {
      if(IsPostBack) return;

      ddlProgrammes.DataSource = new DataAccess().getProgrammes();
      ddlProgrammes.DataBind();
      ddlProgrammes.Items.Insert(0,new ListItem("--Please select--", ""));
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top