2016-02-17 23 views
0

我需要在ASPX(VB版本)中读取POST方法中的变量。用ASPX读取POST变量vb.net

下面的代码:

<!DOCTYPE html> 
<html> 
    <script runat="server"> 
     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
      Response.Write("[POST]<br />") 
      For Each s As String In Request.Form.AllKeys 
       Response.Write("[Request.Form] " & s & ": " & Request.Form(s) & "<br />") 
      Next 
      Response.Write("[GET] <br />") 
      For Each a As String In Request.QueryString.AllKeys 
       Response.Write("[Request.QueryString] " & a & ": " & Request(a) & "<br />") 
      Next 
     End Sub 
</script> 
<body> 
<form action="demo_simpleform.aspx" method="post"> 
    <input name="infob" type="text" value="POST" id="infob" disabled /> 
    <input name="TextBox1" type="text" value="" id="TextBox1" /> 
    <input name="TextBox2" type="password" id="TextBox2" /> 
    <input type="submit" value="Method POST" /> 
</form> 
<form action="demo_simpleform.aspx" method="get"> 
    <input name="infoa" type="text" value="GET" id="infoa" disabled /> 
    <input name="TextBox1a" type="text" value="" id="TextBox1a" /> 
    <input name="TextBox2a" type="password" id="TextBox2a"/> 
    <input type="submit" value="Method GET"/> 
</form> 
</body> 
</html> 

为什么我无法读取POST变量?怎么了? 帮助我,请

+1

那你试试?你的意思是“不能”? – Noy

回答

0

我已经找到了解决方案(但我不明白为什么...)

我必须改变FORM行动=“demo_simpleform.aspx”方法=“后”到FORM RUNAT =”服务器”。 好吧,我知道必须插入runat =“server”参数(在表单声明和所有对象在我的表单内),但为什么我nedd删除action =“demo_simpleform.aspx”method =“post”?

这里的工作代码:

<!DOCTYPE html> 
<html> 
    <script runat="server"> 
     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
      Response.Write("[POST]<br />") 
      For Each s As String In Request.Form.AllKeys 
       Response.Write("[Request.Form] " & s & ": " & Request.Form(s) & "<br />") 
      Next 
      Response.Write("[GET] <br />") 
      For Each a As String In Request.QueryString.AllKeys 
       Response.Write("[Request.QueryString] " & a & ": " & Request(a) & "<br />") 
      Next 
     End Sub 
</script> 
<body> 
<form runat="server"> 
    <input runat="server" name="infob" type="text" value="POST 2" id="infob" disabled /> 
    <input runat="server" name="TextBox1" type="text" value="" id="TextBox1" /> 
    <input runat="server" name="TextBox2" type="password" id="TextBox2" /> 
    <input runat="server" type="submit" value="Method POST 2" /> 
</form> 
<form action="demo_simpleform.aspx" method="get"> 
    <input name="infoa" type="text" value="GET" id="infoa" disabled /> 
    <input name="TextBox1a" type="text" value="" id="TextBox1a" /> 
    <input name="TextBox2a" type="password" id="TextBox2a"/> 
    <input type="submit" value="Method GET"/> 
</form> 
</body> 
</html>