ASP.NET取值的一些小经验

 我刚看到一个帖子,楼主可能初学。

奇怪,Request.Form为什么不能获取html传递来的数据?

http://community.csdn.net/Expert/topic/5716/5716068.xml?temp=.2434198

 

我回复的是

//只有form method="get"时才可用Request.QueryString["one"]方法
        //string one = Request.QueryString["one"];
        //string two = Request.QueryString["two"];

        //只有form method="post"时才可用Request.Form方法,否则出错, action="Response_2.aspx"
        //string one = Request.Form["one"];
        //string two = Request.Form["two"];

        //只有它,才不被post,get方式限制呢。Request.Params好象是2.0新支持的
        string one = Request.Params["one"];
        string two = Request.Params["two"];
        //它也不被post,get方式限制呢。
        //string one = Request["one"];
        //string two = Request["two"];

如果不是服务控件,可能用以下方法取值 
 <input id="Text1" type="text" name="first"/>

Requst.Form["first"] 中 ClientElementName 指的是 html 的 name 属性

希望对更多的初学者有帮助。

对了,对于学的值还要进行,判断
1.0/1.1中
if(Request["one"]==null||Request["one"]==String.Empty)
{
//空的或是NULL
}

2.0中

if(String.IsNullOrEmpty(Request["one"]) == true)
{
//空的或是NULL
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值