2016-02-17 48 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>