关于Page_Load的问题
Page_Load写在aspx中可以执行,写在cs中不被执行,为什么?
aspx文件
======================================
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="xfznet.edit.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Simple Repeated-Value Data Binding</title>
</head>
<body bgcolor="#ffffff">
<span class="heading">Simple Repeated-Value Data Binding</span><hr />
<form runat="server" ID="Form1">
<b><ASP:RadioButtonList></b> control:<br />
<ASP:RadioButtonList id="MyRadioList" runat="server" /><p />
</form>
</body>
</html>
cs文件
=======================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace xfznet.edit
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.RadioButtonList MyRadioList;
public void Page_Load(object sender, System.EventArgs e)
{
ArrayList arrValues = new ArrayList(5);
arrValues.Add("Microsoft");
arrValues.Add("Sun");
arrValues.Add("IBM");
arrValues.Add("Compaq");
arrValues.Add("Oracle");
MyRadioList.DataSource = arrValues;
MyRadioList.DataBind();
}
}
}
问题点数:20、回复次数:5Top
1 楼singlepine(小山)回复于 2005-08-19 23:54:13 得分 15
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
把这段加进去,你少了page的load的注册内容Top
2 楼singlepine(小山)回复于 2005-08-19 23:55:34 得分 0
也就是说,你的页面在load的时没有调用load事件,因为你没有注册它Top
3 楼weisunding(鼎鼎)回复于 2005-08-20 00:05:20 得分 0
楼主对类的概念还没概念吧,建立复习一下类!!!!!Top
4 楼pandahyang(偶在学习.NET)回复于 2005-08-20 00:26:36 得分 5
singlepine(小山) 说的对,你吧vs自己加上的调用页面初始化的删掉了Top
5 楼wangbd8(wangbd8)回复于 2005-08-20 08:05:37 得分 0
谢啦,我以前用jsp,现在需要把1份asp改称asp.net,看的是《asp.net 1.1高级编程》,他用的全是在页面中直接写c#代码,根本没介绍如何将二者分开,所以净出错。而且感觉许多在asp能用的方法,复制到aspx中就不行了。
Top




