开发者

How to POST form in ASP.NET to another page just like HTML post?

I want to POST a form using ASP.NET. How can I do this?

I am new to ASP.NET. In PHP I used <form>'s method attribute, like this:

<form method=开发者_开发知识库"POST" action="..."></form>


See this Snippet Code:

<asp:Button 
  ID="Button1" 
  PostBackUrl="~/TargetPage.aspx"
  runat="server"
  Text="Submit" />

How to: Post ASP.NET Web Pages to a Different Page


You might be also interested in getting the posted page variables as follow:

   public string UserName
   {
      get { return this.tbUsername.Text; }
      set { this.tbUsername.Text = this.sUsername; }
   }

And in the new Page Use:

 string sPostedUserName = (string)PreviousPage.UserName;
 //  you must first get a strongly typed reference to the source page
 <%@ PreviousPageType VirtualPath="~/login.aspx" %>

To get more into this see Cross-Page Posting in ASP.NET Web Pages

There are too many ways of reading the posted variables like Query String:

 string prevPageVar  = Request.QueryString["MyVariable"];


This code will be useful in case of link button

<asp:LinkButton 
  ID="Button1" 
  PostBackUrl="~/target.aspx"
  runat="server"
  Text="Submit" />

For simple button

<asp:Button 
      ID="Button1" 
      onClick="targetPage"
      runat="server"
      Text="Submit" />

Here target page is an event and for it you have to do C sharp coding. You should use following code in "targetpage" event:

Response.Redirect("target.aspx");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜