VB - 按钮单击事件无法正常工作
在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您提供的代码中我们可以看到,您所做的只是改变可见性。您是否在其他地方禁用了该按钮?另请检查设计视图中按钮的属性,以确保您没有意外地将 Enabled 属性更改为“False”。我已经有一段时间没有完成任何 Web 应用程序了,但是如果您要以编程方式更改按钮的启用值,我建议将 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:
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.
尝试使用
SelectedItem.Value
代替,如下所示Try
SelectedItem.Value
instead, like this