简体   繁体   English

C#:按钮onClick C#代码上的HTML表单数据

[英]C#: Html Form data on button onClick C# code

I want to send my HTML Form Action url to post by the C# pragmatically not by the HTML code on click of button action.. 我想通过C#实用地发送我的HTML Form Action URL,而不是单击按钮操作时按HTML代码发送。

<form action="url" method=POST runat="server"></form>

What I am trying is 我正在尝试的是

 <form id="form" method="POST" runat="server">

and in C# code 和在C#代码中

 protected void Button2_Click(object sender, EventArgs e)
    {

    HtmlForm form = (HtmlForm)this.FindControl("form");

      form.Attributes.Add("action", "url");

    }

This does not trigger the action method but url gets added.. how do i trigger call from C# code 这不会触发操作方法,但是会添加网址。.如何触发来自C#代码的调用

Instead of trying to change your form action, you can use "Server.Transfer" to post the form data to a different form: 您可以使用“ Server.Transfer”将表单数据发布到其他表单,而不必尝试更改表单动作:

Server.Transfer(url);

If you don't need to post the form data to the next form and just want to change to a separate URL, use "Response.Redirect" to redirect the browser to whichever page you intend: 如果您不需要将表单数据发布到下一个表单,而只想更改为单独的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM