首页 文章

复选框状态未更改ASP-vb.net

提问于
浏览
0

我想创建一个包含一个图像/按钮的页面 . 当你点击它 . 它会出现一个弹出窗口,里面的复选框很少 . 我想在选中时将复选框的值传递给标签 .

但是当我单击复选框时,复选框的CHECKEDCHANGED事件永远不会发生 . 多数民众赞成我尝试按下按钮,如果按下按钮,则在检查复选框后,调试器将始终显示值为FALSE . 按钮的单击事件将发生,但它将仅显示复选框值为FALSE . 请查看图像,代码,如果需要,我可以提供JS和CSS .

This is the image of the actual webpage. I want to do something that when you click on image it will appear one pop up window. There will be one check box on pop up window. when you change the state of pop up window it should notify user that state has been changed by message box.
default.aspx:

<body style="background-color: #FFFF00">
<form id="form1" runat="server">
    <div>
        <table> 
            <tr> 
                <td>
                    <a id="open-pop-up-2" href="#pop-up-2">
                        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/234.png"/>
                    </a>
                </td> 
            </tr> 
        </table> 
    </div>
    <div id="pop-up-2" class="pop-up-display-content">
        <table style="width:100%;border-style:solid;border-width:1px"> 
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox1" runat="server" Text="Onion" />
                </td>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="Show State" UseSubmitBehavior="false"/>   
                </td> 
            </tr> 
        </table> 
    </div>
</form>

default.aspx.vb:

Imports System.Web.UI
Imports System.Web
Imports System.Data
Partial Class _Default
      Inherits System.Web.UI.Page
      Dim dt1 As New DataTable
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    If CheckBox1.Checked = True Then
        MsgBox("State: Checked")
    ElseIf CheckBox1.Checked = False Then
        MsgBox("State: Unchecked")
    End If
End Sub
Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    If CheckBox1.Checked = True Then
        MsgBox("State: Checked")
    ElseIf CheckBox1.Checked = False Then
        MsgBox("State: Unchecked")
    End If
End Sub
End Class

JS:

$('#open-pop-up-2').click(function (e) {
    e.preventDefault();
    $('#pop-up-2').popUpWindow({
        action: "open",
        buttons: [{
            text: "Yes",
            click: function () {
                this.close();
            }
        }, {
            text: "No",
            click: function () {
                this.close();
            }
        }]
    });
});

2 回答

  • 0

    该复选框必须具有 AutoPostBack="True" ,否则更改事件将不会触发,直到另一个控件导致回发 .

    <asp:CheckBox ID="CheckBox1" runat="server" Text="Onion" AutoPostBack="true" />
    
  • 0

    已经在相同的线程中工作了很长时间并且最终由于棘手的弹出代码[JQ],即使我们将AUTOPOSTBACK设置为true或false,复选框状态的值也永远不会通过 . 所以我不得不改变POP up控件并开发自己的 .

    谢谢 .

相关问题