ASP.NET小技巧.txt

本文介绍了ASP.NET中的多种实用技巧,包括使用Response对象显示JavaScript警告框、关闭浏览器窗口、获取客户端IP地址、解决重定向时汉字乱码问题等,并涵盖了如何操作DropDownList控件的方法。

一.Response对象的Write方法与JavaScript脚本语言的结合使用.(page_51)

弹出提示对话框.
Response.Write("<script>alert('你好!');</script>");

   2.关闭窗口

Response.Write("<script>window.opener=null;window.close();script>");

二.获取客户端IP地址.(page_54)

1. 通过Request的userHosaddress属性.

texBox1.Text=Request.userHosaddress;

2.通过Request的ServerVariabes属性

TexBox1.Text=Request.ServerVariabes["REMOTE_ADDR"];

三.获取当前页面的路径

Response.Redirect(Request.CurrentExecutionFilePath);

四.如何解决Response.Redirect方法传递汉字丢失或乱码问题?(page_66)

传值之前.

String 如何解决Response.Redirect方法传递汉字丢失或乱码问题?");

Response.Redirect("a.aspx?name"+name);

接收时

String name"]);

五.打开新窗口并关闭父窗口.(page_81)

      Response.Write("<script language='javascript'>window.open('NewPage.aspx','','width=335,height=219');window.opener=null;window.close();</script>");

六.打开Outlook.

      把Hyperlink控件的NavigateUrl属性值设置为:mailto:htx206@163.com

七.设为首页.

      把Linkbutton按扭的OnClientClick属性设为:this.style.behavior='url(#default#homepage)';this.sethomepage('http://www.baidu.com')

八.添加到收藏夹.

      把Button控件的OnClientClick属性值为:window.external.addFavorite('http://www.baidu.com','百度')

九.DropDownList的方法(page_95).

1.获取DropDownList控件的索引号和标题.

int Index=DropDownList.SelectedIndex;

string text=DropDownList.SelectedItem;

2.向DropDownList控件的下拉列表框中添加列表项.

DropDownList.Items.Add(new LIstItem("asp.net","0"));

DropDownList.Items.Add(string);

3.删除选择的DropDownList控件的列表项.

ListItem ltem=DropDownList1.Selectedlitem;

DripDownlist1.ltems.Remove(ltem);

4.清除所有DripDownlist控件的列表项.

DripDownlist1.Items.Clear();

5.获取DripDownlist控件包含的列表项数.

int count=DripDownlist.Items.count;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值