开发者

VB - button click event not working properly

开发者 https://www.devze.com 2023-03-07 15:06 出处:网络
In my windows app i have a button which is only visible when a user selects a certain value on a DropDownList.

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 D开发者_运维技巧ropDownList4.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


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消