提交按钮点击

发布于 2024-08-18 12:24:32 字数 59 浏览 3 评论 0 原文

我有用于数据接受的GUI。 我需要在单击提交按钮时将表单的所有参数传递给 C# 中声明的函数。 请帮忙。

I have GUI for data acceptance.
I need to pass all the parameters of the form on click of a submit button to a function declared in C#.
Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑饮青盏花 2024-08-25 12:24:32

使用 .Net,我们有多种类型的提交标记,一种以 开头,另一种以 开头。 runat="server" 属性,您将使其在按钮后面也具有 C# 代码。

Using .Net us have too types of submit tags, one starting with <asp: and the other starting with <input. the <input html tag can call javascript and if you add the runat="server" attribute, you will enable it to also have C# code behind the button.

冷弦 2024-08-25 12:24:32

首先,您需要创建一个 aspx 页面(例如 submission.aspx),用于接收表单的 POST 提交。在该页面中,您可以包含 .cs 文件,其中包含要将数据传递到的方法/函数。

接下来,您要将数据提交到 submission.aspx。为此,您需要一个将数据提交到 submission.aspx 的表单。

<form action='submission.aspx' method='POST' id='data-submission'>
    <!-- stuff here -->
</form>

如果你想执行ajax提交,你可以使用jquery并使用这段代码:

$('#data-submission').submit(function(evt){
    var $form = $(this);
    var url = $form.attr('action');
    $.post(url, $form.serialize(), function(){alert('submission complete!);});
});

我不知道这是否对你有帮助。

PS:我已经很长一段时间没有使用 .NET 进行 Web 编程了。但是我在这个答案中所写的内容对于任何 Web 编程语言/框架都普遍适用。

First of all, you will need to create an aspx page (say submission.aspx) that will receive the POST submission of your form. In that page, you can include your .cs file that contains the method/function you want to pass the data to.

Next, you want to submit you submit your data to submission.aspx. To do that, you will need to have a form which will submit its data to submission.aspx.

<form action='submission.aspx' method='POST' id='data-submission'>
    <!-- stuff here -->
</form>

If you want to perform ajax submission, you can use jquery and use this code:

$('#data-submission').submit(function(evt){
    var $form = $(this);
    var url = $form.attr('action');
    $.post(url, $form.serialize(), function(){alert('submission complete!);});
});

I wonder if all that helped you.

PS: I haven't used .NET for web programming in a long time now.. but what I've written here in this answer hold universally true for any web programming language/framework.

耀眼的星火 2024-08-25 12:24:32

如果你使用asp.net,你只需要双击按钮(如果它是一个asp按钮),它应该会产生一个点击事件。

在单击事件中,您可以获得其他控件,例如

default.aspx 代码

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

Codebehind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    // you can declare it as a field variable so the entire code behind can use it
    private Passengerdetails myClass;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      // create an instance of the class.
       myClass = new Passengerdetails ();
       // stick textbox1 contents in the property called test.
       myClass.PassengerName = TextBox1.Text;


       int a =  Convert.ToInt32(TextBox1.Text);
       int b = Convert.ToInt32(TextBox2.Text);
       int sum = Add(a, b);

       // do something with it like return it to a lbl.
       Label1.Text = sum.ToString();
    }

    private int Add(int a, int b)
    {
        return a + b;
    }
}

Edit。你只要上一堂课就可以了。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for passengerdetails 
/// </summary>
public class Passengerdetails 
{
    public Passengerdetails ()
    {

       public string PassengerName{ get; set; }

    }
}

If your using asp.net you just need to double click the button(if it is an asp button) and it should make a click event.

In the click event you could get your other controls like

default.aspx code

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

Codebehind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    // you can declare it as a field variable so the entire code behind can use it
    private Passengerdetails myClass;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      // create an instance of the class.
       myClass = new Passengerdetails ();
       // stick textbox1 contents in the property called test.
       myClass.PassengerName = TextBox1.Text;


       int a =  Convert.ToInt32(TextBox1.Text);
       int b = Convert.ToInt32(TextBox2.Text);
       int sum = Add(a, b);

       // do something with it like return it to a lbl.
       Label1.Text = sum.ToString();
    }

    private int Add(int a, int b)
    {
        return a + b;
    }
}

Edit. You just make a class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for passengerdetails 
/// </summary>
public class Passengerdetails 
{
    public Passengerdetails ()
    {

       public string PassengerName{ get; set; }

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文