[英]C#: Html Form data on button onClick C# code
我想通過C#實用地發送我的HTML Form Action
URL,而不是單擊按鈕操作時按HTML
代碼發送。
<form action="url" method=POST runat="server"></form>
我正在嘗試的是
<form id="form" method="POST" runat="server">
和在C#代碼中
protected void Button2_Click(object sender, EventArgs e)
{
HtmlForm form = (HtmlForm)this.FindControl("form");
form.Attributes.Add("action", "url");
}
這不會觸發操作方法,但是會添加網址。.如何觸發來自C#代碼的調用
您可以使用“ Server.Transfer”將表單數據發布到其他表單,而不必嘗試更改表單動作:
Server.Transfer(url);
如果您不需要將表單數據發布到下一個表單,而只想更改為單獨的URL,請使用“ Response.Redirect”將瀏覽器重定向到您想要的任何頁面:
Response.Redirect(url);
<!DOCTYPE html>
<html>
<body>
<button type="button" onclick="THIS IS WHERE YOU PUT THE CODE">Send Info</button>
<p>This is the code:
<!DOCTYPE html>
<html>
<body>
<button type="button" onclick="alert('')">Send Info</button>
</p>
<p> If this code doesn't show, inspect it...
</body>
</html>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.