首页 > 解决方案 > 如何知道在表单中单击了哪个命令按钮

问题描述

我有一个包含 3 个命令按钮的表单。我想知道单击了哪个命令按钮并将值存储在会话变量中如何做到这一点。

我在会话变量中得到空值

<form method="post" name = "theform" >
  <table>
    <tr>
         <td align="left" width="100%">
             <input type="submit" name = "button" id ="idbutton1" value="Value1">      
              </td>
         <td align="left" width="100%">
             <input type="submit" name = "button" id ="idbutton2" value="Value2">
              </td>

        <td align="left" width="100%">
             <input type="submit" name = "button" id ="idbutton3" value="Value3">
              </td>
       </tr>
</table>
</form>

Session("type")=Request.Form("button") 

标签: htmlasp-classic

解决方案


您需要Request.Form("button")在将其分配给会话变量之前检查它是否包含一个值,否则您将在Session("type")每次页面加载时为其分配一个空字符串值。

if request.form("button") <> "" then Session("type") = Request.Form("button")

推荐阅读