2014-03-19 19 views
-5

你好,我想爲我的表單找到'C#必填字段驗證'。任何人都可以幫助我與C#所需的提交驗證碼?

任何人都可以給我一些想法嗎?

有10個文本框和1個插入按鈕,我想要建立的是一個獨立的應用程序。

+0

你想做什麼驗證?請告訴我們你的代碼。 – ElectricRouge

+0

他要求必填字段驗證。 –

+0

是的,我正在尋找所需的字段驗證,如果用戶沒有把公司名稱...在他的txt框的一邊,他會看到請輸入一個公司名稱pls ...這個東西很容易在web應用程序,如PHP或asp.net,但在C#上,我不知道,如果有什麼你推薦...讓我知道謝謝。 – Bisrat

回答

0

C#代碼驗證

protected void btnSubmitForm_Click(object sender, EventArgs e) 
{ 
    if(txtSome.Text.Length==0) 
    { 
     label.Text = "your message for Required feild!"; 
    } 
    else if(txt2.Text.Length==0) 
    { 
     label.Text = "your message for Required feild!"; 
    } 
    else 
    { 
    //write code here to insert values in database. this block of code will be executed when your all text boxes will have some code. 
    } 
} 
+0

好的Aftab謝謝你的代碼,但是在這個獨立的應用程序項目中,你是否有任何想法驗證文本框,例如,如果你沒有在文本框中插入任何東西,並點擊插入,在文本框的一邊你會看到爲文本框添加一些值或者請將名稱添加到文本框中... – Bisrat

+0

確定以便您使用Windows應用程序。在文本框前放一個標籤。並在按鈕單擊事件檢查如果(textbox.length == 0){label.text =「Your message」;} –

+0

此代碼工作正是我想要的!謝謝Aftab艾哈邁德 – Bisrat

0

的RequiredFieldValidator:

<asp:RequiredFieldValidator runat="server" ForeColor="Red" Display="Dynamic" ControlToValidate="YourControl" ErrorMessage="Error Message!!!!"></asp:RequiredFieldValidator> 
+0

他正在使用Windows應用程序。 –

+1

@AtabtabAhmed爲什麼asp.net標籤呢? – gsharp

+0

我不知道,但他正在尋找Windows應用程序的解決方案。首先我還使用了asp.net所需的字段驗證器。 –

0

嘗試是這樣的

的.aspx

<asp:TextBox runat="server" id="txtName" /> 
<asp:Button runat="server" id="btnSubmitForm" text="submit" onclick="btn_ClickSubmit" /> 

的.cs

System.Web.UI.WebControls.TextBox txtName; 

protected void btn_ClickSubmit(object sender, Eventargs e) 
{ 
if(txtName.Text =="") 
    { 
    MessageBox.Show("Textbox is required"); 
    } 
} 
相關問題