本文介绍了如何正确获取HtmlInputSubmit控件ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有2个html表单提交按钮.
我需要在C#服务器端获取html提交按钮的ID.
而且,它是纯html且OnServerClick ="Button_PlaceOrder" runat =服务器"不允许.

如何正确获取HtmlInputSubmit控件ID?

input.html

< form name =" Form1" method ="post"动作="inputform.aspx"; id ="Form1">
<输入类型=提交" value ="PlaceOrder"; id ="PlaceOrder"; />  
<输入类型=提交" value ="CancelOrder" id ="CancelOrder" />
</form>


inputform.aspx.cs

受保护的无效Page_Load(对象发送者,EventArgs e)
        {
           字符串c = Request ["PlaceOrder"]; //null
            HtmlForm form =(HtmlForm)FindControl("Form1"); //有对象

            HtmlButton PlaceOrder1 =(HtmlButton)form.FindControl(" PlaceOrder); //null
            HtmlInputSubmit PlaceOrder2 =(HtmlInputSubmit)form.FindControl("PlacePlace"); //null
            HtmlInputButton PlaceOrder3 =(HtmlInputButton)form.FindControl("PlaceOrder"); //null
           
          HtmlButton PlaceOrder4 =(HtmlButton)FindControl("PlacePlace"); //null
            HtmlInputSubmit PlaceOrder5 =(HtmlInputSubmit)FindControl("PlaceOrder"); //null
            HtmlInputButton PlaceOrder6 =(HtmlInputButton)FindControl(" PlaceOrder); //null

            PlaceOrder1.Click + = new EventHandler(Button_PlaceOrder);
        }

       受保护的void Button_PlaceOrder(对象发送者,EventArgs e)
      {
           字符串a =";
        }

There are 2 submit buttons in a html form.
I need to get the id of html submit buttons in C# server side.
And, it is pure html and OnServerClick="Button_PlaceOrder" runat="server" is not allowed.

How should I get the HtmlInputSubmit control ID properly?

input.html

<form name="Form1" method="post" action="inputform.aspx" id="Form1">
<input type="submit" value="PlaceOrder" id="PlaceOrder" />  
<input type="submit" value="CancelOrder" id="CancelOrder" />
</form>


inputform.aspx.cs

protected void Page_Load(object sender, EventArgs e)
        {
            string c = Request["PlaceOrder"]; //null
            HtmlForm form = (HtmlForm)FindControl("Form1"); //has object

            HtmlButton PlaceOrder1 = (HtmlButton)form.FindControl("PlaceOrder"); //null
            HtmlInputSubmit PlaceOrder2 = (HtmlInputSubmit)form.FindControl("PlaceOrder"); //null
            HtmlInputButton PlaceOrder3 = (HtmlInputButton)form.FindControl("PlaceOrder"); //null
           
          HtmlButton PlaceOrder4 = (HtmlButton)FindControl("PlaceOrder"); //null
            HtmlInputSubmit PlaceOrder5 = (HtmlInputSubmit)FindControl("PlaceOrder"); //null
            HtmlInputButton PlaceOrder6 = (HtmlInputButton)FindControl("PlaceOrder"); //null

            PlaceOrder1.Click += new EventHandler(Button_PlaceOrder);
        }

        protected void Button_PlaceOrder(object sender, EventArgs e)
        {
            string a = "";
        }

推荐答案

请注意,ASP.NET确实有一个单独的论坛.考虑它,以便将来获得ASP.NET问题以获取最佳答案: http://forums.asp.net/

Note that ASP.NET really has a separate forum.  Consider it for future ASP.NET questions to get the best answers: http://forums.asp.net/

 


这篇关于如何正确获取HtmlInputSubmit控件ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 01:38