ASP.NET2.0应用开发新特性小技巧

跨越面提交CrossPagePostback

page1页面

<asp:Button ID="lblSearch" runat="server" PostBackUrl ="~/Search.aspx"
            Text="Search" Height="26px" Width="75px" onclick="lblSearch_Click"
/>

Search.aspx页:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsCrossPagePostBack)
        {
           this.Label1 .Text ="不是跨页面提交的!"
        }

        else
        {
            TextBox SearchTerm = new TextBox();
            SearchTerm = ((TextBox)Page.PreviousPage.FindControl("txtSearchTerm"));
            Label1.Text = "您要搜索的是:" + SearchTerm.Text;
        }
   }

 

 

验证分组功能

<asp:Button ID="Button2" runat="server" Text="Search" PostBackUrl="Search.aspx" ValidationGroup="Search" />
      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" SetFocusOnError="true" Runat="server" ErrorMessage="Search is empty!!"
ControlToValidate="SearchTerm" ValidationGroup="Search" />

焦点设置Focus

<form id="form1" DefaultButton="Button1" DefaultFocus="TextBox2" runat="server">

Page.SetFocus(TextBox1)

TextBox4.Focus()

设置DefaultButton

<form id="form1" defaultfocus="TextBox1" defaultbutton ="Button2" runat="server">

<asp:Panel ID="Panel1" DefaultButton ="Button3" Visible ="true" runat="server" Height="90px">

添加客户端脚本

<asp:Button ID="Button1" OnClientClick='javascript:alert("clicked!")' Text="Click Me!" runat="server" OnClick="Button1_Click"/>

保存滚动条位置

<%@ Page Language="VB" MaintainScrollPositionOnPostBack="true" %>

你可能感兴趣的:(asp.net)