[How Do I] Learn the Tips and Tricks of Experts

1.获取前一个页面的信息:

Page1:

 

代码
   
     
< form id = " form1 " runat = " server " defaultbutton = " Button1 " defaultfocus = " TextBox1 " >
< div >

< asp:TextBox ID = " TextBox1 "
runat
= " server " >
</ asp:TextBox >
< br />
< asp:Calendar ID = " Calendar1 "
runat
= " server " >
</ asp:Calendar >
< br />
< asp:Button ID = " Button1 "
runat
= " server "
PostBackUrl
= " ~/Page2.aspx "
Text
= " Button " />
</ div >
</ form >

Page2:

 

 

代码
   
     
protected void Page_Load( object sender, EventArgs e)
{
if ( ! Page.IsPostBack)
{
TextBox t
= ((TextBox)(PreviousPage.FindControl( " TextBox1 " )));
Calendar c
= ((Calendar)(PreviousPage.FindControl( " Calendar1 " )));
Label1.Text
= string .Format( " Hello {0},you clicked on {1} " ,t.Text ,c.SelectedDate );
}
}

2.几种控件用法:

 

代码
   
     
< div >
< asp:RadioButtonList ID = " RadioButtonList1 "
runat
= " server "
AutoPostBack
= " True "
RepeatDirection
= " Horizontal "
onselectedindexchanged
= " RadioButtonList1_SelectedIndexChanged " >
< asp:ListItem Value = " 0 " > Bulleted List </ asp:ListItem >
< asp:ListItem Value = " 1 " > File Upload </ asp:ListItem >
< asp:ListItem Value = " 2 " > URL Mapping </ asp:ListItem >
</ asp:RadioButtonList >< br />


< asp:MultiView ID = " MultiView1 "
runat
= " server " >
< asp:View ID = " View1 " runat = " server " >

Bulleted List Control
< br />
< asp:BulletedList ID = " BulletedList1 "
runat
= " server "
DataSourceID
= " XmlDataSource1 "
DataTextField
= " text "
DataValueField
= " url "
DisplayMode
= " HyperLink " >
</ asp:BulletedList >

</ asp:View >
< asp:View ID = " View2 " runat = " server " >

File Upload Control
< br />
< asp:FileUpload ID = " FileUpload1 " runat = " server " />
< br />
< asp:Button ID = " Button1 " runat = " server " onclick = " Button1_Click " Text = " UpLoad " />
< br />
< asp:HyperLink ID = " HyperLink1 " runat = " server " > HyperLink </ asp:HyperLink >

</ asp:View >
< asp:View ID = " View3 " runat = " server " >

URL mapping
< br />
< a href = " guid_{492f3e0b-848e-11da-9550-00e08161165f}.htm " >
guid_{492f3e0b
- 848e - 11da - 9550 - 00e08161165f }.htm </ a >< br />
< br />
< a href = " guid.htm " > guid.htm </ a >
< br />

</ asp:View >
</ asp:MultiView >

< asp:XmlDataSource ID = " XmlDataSource1 " runat = " server "
DataFile
= " ~/hyperlinks.xml " ></ asp:XmlDataSource >
</ div >

代码
   
     
protected void Button1_Click( object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(
this .MapPath( " upload\\ " + FileUpload1.FileName));
HyperLink1.Text
= FileUpload1.FileName;
HyperLink1.NavigateUrl
= ( " upload\\ " + FileUpload1.FileName);
}

}

protected void RadioButtonList1_SelectedIndexChanged( object sender, EventArgs e)
{
MultiView1.ActiveViewIndex
= Convert.ToInt32(RadioButtonList1.SelectedValue);
}

 

代码
   
     
< system .web >
<!--
设置 compilation debug="true" 可将调试符号插入
已编译的页面中。但由于这会
影响性能,因此只在开发过程中将此值
设置为 true。
-->
< urlMappings enabled ="True" >
< add url ="~/guid.htm" mappedUrl ="guid_{492f3e0b-848e-11da-9550-00e08161165f}.htm" />
</ urlMappings >

 

 

 

 

你可能感兴趣的:(tips)