【问题标题】:how to perform the action when clicking the html submit button without using runat server在不使用 runat 服务器的情况下单击 html 提交按钮时如何执行操作
【发布时间】:2015-07-28 13:23:09
【问题描述】:

当我在不使用 runat 服务器的情况下单击 html 提交按钮时如何执行操作。我必须在哪里编写代码以及我必须写什么。请帮我。我有以下代码:

<table>
        <tr>
            <td>Enter User Id</td>
            <td><input type="text" id="txtUserId" name="userId"/></td>
        </tr>
        <tr>
            <td>Enter Password</td>
            <td><input type="password" id="txtPassword" name="password"/></td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" id="chkRememberMe" />
                <label for="chkRememberMe">Remember Me</label>
            </td>
        </tr>
        <tr>
            <td><input type="Submit" id="btnSubmit" value="Login" name="submitButton"/></td>
        </tr>
    </table>

我想在 *aspx.cs 文件中编写逻辑。谢谢。

【问题讨论】:

  • 为什么你不想使用runat server for button??还有你的项目使用的是哪个 asp.net 框架?

标签: c# html asp.net


【解决方案1】:

任何返回到服务器的页面的 http post 都会触发你的代码隐藏执行,不管你是否有 runat="server" 。您可以通过检查 Page 对象的 IsPostback 属性来检测这一点。

所有 asp.net 按钮都是“提交”按钮。通常,您会希望在您的按钮上有一个 runat="server" 属性,以便您可以在代码隐藏中处理该特定按钮的事件。虽然我只能想到一些不选择的原因,但通常引用的主要原因是 runat="server" 导致控件 ID 发生更改,因此在客户端脚本和 CSS 中它是不可预测的。如果这是您的原因,您可以在该控件上将 clientidmode 设置为 static。

【讨论】:

  • 感谢 Bernesto 的回复。你的解释很好。我同意你的看法。所以,最后我将使用asp.net服务器按钮控件。没关系。我只想知道一件事是我无法从您的解释中理解第二段的最后两行。您能否提供一些有关这些行的简要信息。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-26
相关资源
最近更新 更多