ASP.NET学习心的

来源:互联网 发布:微信网站制作软件 编辑:程序博客网 时间:2024/05/02 10:58

Asp.Net学习心得 1.页面回传机制:回传是在服务器端控件事件触发时,客户端(Web浏览器)向服务器发出通知的一种机制。如果在客户端触发了某种事件(例如点击某代码),那么与该事件相关的数据就会被回传到服务器,并通过服务器端的代码进行处理(后置代码文件中的C#代码)     例如,某访问者点击BUTTON控件时,与该事件相关的数据就会被传回服务器。服务器端就会执行按钮的Click事件方法,执行结果将以HTML代码的方式传回客户端。     每次触发这样的事情时,ASP.NET页面和所有控件(包括用户控件)就会重新载入,并执行Page_Load事件。在任何数据驱动的应用程序中,Page_Load事件很可能会访问数据库,以将相关信息填充到页面中。     page.IsPostBack值为true:触发回传机制     page.IsPostBack值为false:没有触发该机制,表明该页面为第一次被加载2.Request.QueryString用于页面间传值这个是request对象的一个属性负责读取以get方式传递的参数  protected void Page_Load(object sender, EventArgs e)    {        //don't repopulate control on postbacks        if (!IsPostBack)        {            //tie the search text box to the Go button            Utilities.TieButton(this.Page, searchTextBox, goButton);            //load search box controls' values            string allWords = Request.QueryString["AllWords"];//allWords值为allWordsCheckBox.Checked.ToString()            string searchString = Request.QueryString["Search"];//searchString值为searchTextBox.Text            if (allWords != null)                allWordsCheckBox.Checked = (allWords.ToUpper() == "TRUE");            if (searchString != null)                searchTextBox.Text = searchString;        }    }    protected void goButton_Click(object sender, EventArgs e)    {        ExcuteSearch();           }    private void ExcuteSearch()    {        if (searchTextBox.Text.Trim() != "")            Response.Redirect(Request.ApplicationPath + "/Search.aspx?Search=" + searchTextBox.Text +                "&AllWords=" + allWordsCheckBox.Checked.ToString());    }3.GridView的DataKeyNames属性

原创粉丝点击