日期:2014-05-19  浏览次数:20481 次

使用Request时,总是提示<未将对象引用设置到对象的实例>到底是那里的问题?
long.htm   代码如下:
 
<form   action   =   "webform.aspx "   method   =   "post "   >
<input   id= "txtUserName "   type= "text "   /> </td>
                        </tr>
<input   id= "txtPassword "   type= "text "   /> </td>
                        </tr>
<input   id= "Submit1 "   type= "submit "   value= "提交 "   /> </td>
                        </tr>
                </table>
        </div>
</form>
</body>
</html>
///////////////////////////////////////////
webform.aspx.cs   文件里面的代码:

public   partial   class   webform:   System.Web.UI.Page
{
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                string   username   =   Request[ "txtUserName "].ToString();
                string   password   =   Request   [ "txtPassword "].ToString();

                Response.Write(username   +   password);

        }
}
//////////////////////////
每次运行提交时,会提示 <未将对象引用设置到对象的实例> 怎么办呀??

------解决方案--------------------
<input name= "txtUserName " type= "text " /> </td>
</tr>
<input name= "txtPassword " type= "text " /> </td>
------解决方案--------------------
孟大哥说了,这样应该就可以了,为了保险,其实可以把name= "txtUserName "和id= "txtUserName "都写上,呵呵,我有时候就这样