VB - 按钮单击事件无法正常工作

发布于 2024-11-09 11:54:06 字数 800 浏览 0 评论 0原文

在我的 Windows 应用程序中,我有一个按钮,仅当用户在 DropDownList 上选择某个值时才可见。

由于某种原因,当我单击该按钮时,该按钮不起作用。

我已在页面加载时启用该按钮并且它可以工作,但是当我选择下拉列表上的值时该按钮不起作用。

我这里缺少什么吗?如有任何反馈,我们将不胜感激。感谢

码:

Protected Sub DropDownList4_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList4.SelectedIndexChanged
    If DropDownList4.SelectedValue = "Yes" Then
        btnInsert.Visible = True
    Endif
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnInsert.Click
    Response.Redirect("Menu.aspx")
    DropDownList4.SelectedValue = "Yes"
    txtfirstName.Text = ""
    txtSurname.Text = ""
    txtJobTitle.Text = ""
    txtCountry.Text = ""
    txtWork.Text = ""
    DropDownList7.SelectedValue = ""
End Sub

In my windows app i have a button which is only visible when a user selects a certain value on a DropDownList.

For some reason the button does not work when i click on it.

I've enabled the button on page load and it works, however when i choose the value on the Dropdownlist the button does not work.

Is there something im missing here? any feedback would be greatly appreciated. Thanks

Code:

Protected Sub DropDownList4_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList4.SelectedIndexChanged
    If DropDownList4.SelectedValue = "Yes" Then
        btnInsert.Visible = True
    Endif
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnInsert.Click
    Response.Redirect("Menu.aspx")
    DropDownList4.SelectedValue = "Yes"
    txtfirstName.Text = ""
    txtSurname.Text = ""
    txtJobTitle.Text = ""
    txtCountry.Text = ""
    txtWork.Text = ""
    DropDownList7.SelectedValue = ""
End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩起发的微风 2024-11-16 11:54:06

从您提供的代码中我们可以看到,您所做的只是改变可见性。您是否在其他地方禁用了该按钮?另请检查设计视图中按钮的属性,以确保您没有意外地将 Enabled 属性更改为“False”。我已经有一段时间没有完成任何 Web 应用程序了,但是如果您要以编程方式更改按钮的启用值,我建议将 Enabled = True 行添加到您选择的索引更改子例程中:

如果 DropDownList4.SelectedValue =“是”
然后
btnInsert.Visible = True
btnInsert.Enabled = True
结束

对我来说已经有一段时间了,所以我不记得它是 .Enabled 还是其他。

也有可能您的按钮上有一个面板或类似的东西,这会阻止您实际单击该按钮。

另外,在按钮单击事件的第一行放置一个断点,并确保您没有到达那里,而不是输入代码并且它没有按您期望的方式运行。

From what we can see from your provided code all you are doing is changing visibility. Are you disabling the button anywhere else? Also Check the properties of the button in the design view to ensure that you did not accidentally changed the Enabled property to "False". It has been a while since I have done any web applications but if you are programically changing the enabled value of the button, I would suggest adding an Enabled = True line to your selected index change subroutine:

If DropDownList4.SelectedValue = "Yes"
Then
btnInsert.Visible = True
btnInsert.Enabled = True
Endif

It has been a while for me so I can't remember if it is .Enabled or something else.

There is also the possibility that you have a Panel or some such over your button and that is preventing you from actually clicking on the button.

Also, put a break point on the first line of your button click event and make sure that you are not getting there as opposed to entering the code and it not running the way you expect.

放肆 2024-11-16 11:54:06

尝试使用 SelectedItem.Value 代替,如下所示

Protected Sub DropDownList4_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList4.SelectedIndexChanged
    If DropDownList4.SelectedItem.Value = "Yes" Then
        btnInsert.Visible = True
    Endif
End Sub

Try SelectedItem.Value instead, like this

Protected Sub DropDownList4_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList4.SelectedIndexChanged
    If DropDownList4.SelectedItem.Value = "Yes" Then
        btnInsert.Visible = True
    Endif
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文