2012-09-05 48 views
3

enter image description here採用多種形式,一個ASP.NET Web窗體頁上提交按鈕

我有3個不同的提交按鈕(登錄,搜索,插件)在同一頁,我想要的是找到最好的辦法當我按下它們時,讓這3個按鈕可以做不同的事情,或者在我即將按下時按下Enter鍵。 正如您從我的照片中看到的,當我按Log In時,也會按下插入,因爲我的主頁中有一個global form

我試圖使用不同的形式,但我不能,因爲我需要他們有runat="server",這是不可能的一頁。

我用asp Texboxes:

<asp:TextBox class="text-input" ID="txtLoginEmail" runat="server" 
Height="15px" Width="130px"></asp:TextBox> 

和ASP按鈕:

<asp:Button class="submit google-button" ID="btnLogin" onclick="btnLogin_Click" 

runat="server" Text="Log in" /> 

,除了我的搜索按鈕,這是LinkBut​​ton的:

<asp:LinkButton ID="searchLink" runat="server" onclick="searchLink_Click">Search</asp:LinkButton> 
+0

檢查其中哪些人進行了回傳。 (發件人參數)。除此之外,請看看Model View Presenter。這是使用webforms的一個好方法 –

回答

2

您可以使用Validation Groups導致只要求文本框驗證特定的按鈕點擊。然後在具體按鈕的事件處理程序中,您可以執行特定的邏輯。

+0

在大多數類似的情況下,您可以使用'CausesValidation = false',但在這裏似乎每個按鈕都有它自己的一組驗證,所以組確實是正確的解決方案。 – Servy

+0

我需要更多,我還需要長度檢查和equalsTo檢查(確認密碼)。 –

+0

您可以使用RegularExpressionValidator(例如^ [\ w \ s] {1,50} $)檢查字符串長度。對於等於你可以使用CompareValidator(http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.comparevalidator.aspx) –