2014-10-07 63 views
0

我有四個單獨的部分,我希望在頁面中處理表單提交(當用戶代理處於移動時,顯示部分#1和#2):如何在asp.net中處理不同的表單提交webform

單元#1(移動:

<div id="mSearchB" class="mSearchTextHolder"> 
    <div class="mSearchInnerTextHolder"> 
     <input type="search" placeholder="Search" class="txtMSearch" id="txtMSearch" /> 
    </div> 
</div> 

圖片#1:

enter image description here

節#2(移動):

<div class="brClear loginHolder floatLeft"> 
    <input type="text" placeholder="Username" id="txtUsername" class="txtUsername styledTB floatLeft" /> 
</div> 
<div class="floatLeft"> 
    <input type="password" placeholder="Password" id="pwPassword" class="txtPassword styledTB floatLeft" /> 
</div> 
<div class="floatLeft"> 
    <a href="JavaScript:void(0);" title="Login" class="styledBtn logBtn floatLeft lightLinks">Login</a> 
</div> 

(圖像#2還沒有被建立但類似於#1)

節#3(非移動):

<div class="searchBox"> 
    <input type="text" value="" placeholder="Search" id="searchB" /> 
    <a href="JavaScript:void(0);" title="Search"><img src="theImages/searchWhite.png" alt="Search" title="Search" class="searchImg" /></a> 
</div> 

節#4(非移動):

<div class="brClear loginHolder"> 
    <input type="text" placeholder="Username" id="txtUsername" class="txtUsername styledTB floatLeft" /> 
    <input type="password" placeholder="Password" id="pwPassword" class="txtPassword styledTB floatLeft" /> 
    <a href="JavaScript:void(0);" title="Login" class="styledBtn logBtn floatLeft lightLinks">Login</a> 
</div> 

圖片爲#3和#4:

enter image description here

對於#3和#4,如果我單擊搜索圖標,則所有三個文本框都佔位符空白。

我還沒有放置任何form標籤圍繞上述任何一個,因爲asp.net頁面已經有一個自動插入創建頁面。

如何單獨處理每個提交,因此單擊或按一個文本框中的輸入不會提交整個表單?

+0

這是WebForms? (聽起來就像這樣,根據你如何描述'form'標籤)。如果是這樣,那麼你不要把它們分開。在服務器端代碼中,對於不同的按鈕,您將擁有不同的點擊處理程序,但這只是一種形式導致一個回發。 – David 2014-10-07 13:04:32

+0

是的,它是一個網頁表單。 – SearchForKnowledge 2014-10-07 13:05:13

+0

那麼,讓每個按鈕都是一個服務器端控件,然後分別使用每個點擊?那麼在單獨的文本框上輸入「什麼」? – SearchForKnowledge 2014-10-07 13:06:00

回答

2

我沒有放置任何表單標籤,因爲asp.net頁面已經有一個自動插入頁面創建。

聽起來像WebForms。在這種情況下,基本上,你不要分開你的表單帖子。整個頁面是一個大表單,任何回發觸發事件都會將整個表單提交給服務器。

它在WebForms中完成的方式是爲單獨的按鈕提供單獨的服務器端單擊事件處理程序。所以,如果「子表單1」具有Button1和「子表單2」 Button2那麼每個將有自己的服務器端處理:

void Button1_Click(Object sender, EventArgs e) 
{ 
    // Button1 was clicked, handle it here 
} 

void Button2_Click(Object sender, EventArgs e) 
{ 
    // Button2 was clicked, handle it here 
} 

至於「默認」點擊行動壓在其他控件或輸入像這樣的事情,您可以將每個「子表單」包裝在Panel控件中,並設置its DefaultButton property

+0

我看了這篇文章(http://forums.asp.net/t/1423067.aspx?More+than+one+form+on+a+page+),這也有幫助。謝謝 – SearchForKnowledge 2014-10-07 13:16:54

+0

我可以在按鈕點擊處理程序中添加'action'嗎? – SearchForKnowledge 2014-10-07 13:18:31

+1

@SearchForKnowledge:我不確定你的意思。什麼是'行動'?如果您引用了「form」的「action」屬性,則WebForms頁面始終會回發給自己。您不必擔心form標籤的'action'屬性。 – David 2014-10-07 13:20:36

相關問題