我有用於數據接受的GUI。 我需要將單擊提交按鈕時表單的所有參數傳遞給在C#中聲明的函數。 請幫忙。提交按鈕點擊
Q
提交按鈕點擊
-1
A
回答
0
如果你使用asp.net,你只需要雙擊按鈕(如果它是一個asp按鈕),它應該發出一個點擊事件。
Click事件中,你可以得到你的其他控件像
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>
代碼隱藏
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;
}
}
編輯。你只是上一堂課。
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; }
}
}
0
使用.NET我們有太多類型提交標籤,一個開始<asp:
和其他開始<input
。 <輸入html標記可以調用javascript,如果添加runat="server"
屬性,則可以使其在按鈕後面也具有C#代碼。
+0
嘿朋友我不需要asp.net 在c sharp我想獲得在文本框中輸入的細節到類的變量單擊GUI上的按鈕... – Rookie 2010-01-14 06:14:14
0
首先,您需要創建一個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進行網絡編程了......但是我在這裏寫的這個答案在任何網絡編程語言/框架中都普遍適用。
相關問題
- 1. VBA提交按鈕點擊
- 2. 當點擊提交按鈕
- 3. 點擊提交按鈕
- 4. 點擊提交後按鈕
- 5. jQuery:ajax,點擊提交按鈕
- 6. 在點擊提交按鈕時提交
- 7. 點擊提交按鈕後點擊f5
- 8. 表單提交,雖然點擊按鈕不是提交按鈕
- 9. 形式輸入按鍵提交或點擊提交按鈕
- 10. 上點擊提交按鈕移動itsplace
- 11. JQuery上點擊或提交按鈕
- 12. 點擊後隱藏提交按鈕
- 13. 防止快速提交按鈕點擊?
- 14. HtmlUnit按鈕點擊不提交
- 15. 多提交按鈕點擊問題?
- 16. 不重裝當點擊提交按鈕
- 17. PHP - 確定提交按鈕點擊
- 18. Struts2的Autocompleter - 提交按鈕被點擊
- 19. JQuery的:攔截點擊提交按鈕
- 20. 使用上點擊提交按鈕
- 21. PhantomJS按鈕點擊和表單提交
- 22. 自動化點擊提交按鈕
- 23. 按鈕點擊提交只在Firefox
- 24. 如何在點擊提交按鈕
- 25. 上點擊按鈕時提交表單
- 26. 使提交按鈕消失點擊時
- 27. 點擊提交按鈕時查看sql
- 28. 點擊按鈕,填寫並提交
- 29. 點擊並提交按鈕ID與jquery
- 30. 爪哇 - SWT - 在點擊提交按鈕
你需要解釋一點*(更多地閱讀)*,並且展示一些我們可以幫助的代碼。 – 2010-01-14 05:54:58
您是否使用ASP.NET,如果是這樣,它可能會有所幫助,如果你張貼一些代碼? – Kane 2010-01-14 05:55:42
在我的GUI中,我已經提供了輸入用戶詳細信息,即姓名,地址,年齡的規定。我已經提供的表格上的按鈕,其上點擊應當分配在C尖銳私人無效btnSubmit_Click所有的細節在類 – Rookie 2010-01-14 05:57:37