2014-10-07 35 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

相关问题