使html表单在asp.net中发布数据 [英] Making html form to post data in asp.net

查看:72
本文介绍了使html表单在asp.net中发布数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单设计结构如下



< page>

< form id =mainformrunat =server >

< / form>

My form design structure is as follows

<page>
<form id ="mainform" runat="server">
</form>



< form id =addform>

< asp:Buttonid =okonClick =ok_click/>

< / form>



问题是确定点击它没有执行ok_click,因为第二种形式没有runat属性。

我们无法在服务器上运行两个表格,因为我的主要形式正在运行服务器端我无法生成第二个表格在服务器上运行。



你能告诉我怎样才能让oK_click来执行。



我尝试了什么:



我按OK按钮作为HTML按钮。仍然无效

<form id="addform">
<asp:Button" id="ok" onClick="ok_click"/>
</form>

Problem is on OK click its not executing ok_click due to 2nd form does not have runat attribute.
We couldnt make two form run at server at onece as my mainform is running server side I could not make 2nd form to run at server .

Could you tell me please how can I make oK_click to eexecute.

What I have tried:

I made OK button as HTML button.Still not working

推荐答案

您需要将其中一个作为普通表单(没有runat = server),并且其中的元素正常html控件,如< input>和< select>,并阅读控制v使用Request.Form。或者你有一个单独的表单与runat = server并将所有控件放在其中。您可以使用asp:Panel控件来帮助使控件像他们自己的形式一样。



You either need to make one of them a normal form (no runat=server) and the elements inside it normal html controls like <input> and <select>, and read the control values using Request.Form. Or you have a single form with runat=server and put all the controls inside it. You can use asp:Panel controls to help make the controls act as if they are in their own form.

<form id="form1" runat="server">
    <asp:Panel runat="server" DefaultButton="ButtonOne">
        <asp:TextBox ID="txtOne" runat="server" />
        <asp:Button ID="ButtonOne" runat="server" Text="One" OnClick="ButtonOne_Click" />
    </asp:Panel>

    <asp:Panel runat="server" DefaultButton="ButtonTwo">
        <asp:TextBox ID="txtTwo" runat="server" />
        <asp:Button ID="ButtonTwo" runat="server" Text="Two" OnClick="ButtonTwo_Click" />
    </asp:Panel>
</form>


添加到解决方案1 ​​...

HTML确实支持多个表单标签(甚至不鼓励),ASP.NET不支持它......

这是你在设计页面时必须考虑的事情......

(要正确...你可以拥有多个表格并且可以修复后退问题也是如此,但是你不会从ASP.NET获得任何帮助处理这些形式的框架,所以最好不要使用它们)
To add to solution 1...
It is true that HTML does support multiple form tags (even not encourages), ASP.NET does not support it...
It is something you have to consider when designing your pages...
(To be correct...You can have more than one form and can fix the post-back problem too, but you will not get any help from the ASP.NET framework to deal with those forms, so it better not to use them)


这篇关于使html表单在asp.net中发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆