Button OnClick not firing on first click

S

SAL

Hello,
I have a button on a webform that has an OnClick event defined as such:

<asp:Button ID="btnSearchByName" runat="server" Text="Search By Name"
OnClick="btnSearchByName_Click" Width="152px" EnableViewState="False"
CausesValidation="False" />

the btnSearchByName_Click event fires the second time the button is clicked
but not the first. Is there something I'm missing on getting the thing to
fire the first time it's clicked instead of the second time?

Thanks
S
 
G

Guest

Hello,
I have a button on a webform that has an OnClick event defined as such:

<asp:Button ID="btnSearchByName" runat="server" Text="Search By Name"
OnClick="btnSearchByName_Click" Width="152px" EnableViewState="False"
CausesValidation="False" />

the btnSearchByName_Click event fires the second time the button is clicked
but not the first. Is there something I'm missing on getting the thing to
fire the first time it's clicked instead of the second time?

what's the code of btnSearchByName_Click?
 
S

SAL

Public Sub btnSearchByName_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim abll As New AnnexationsBLL
If Not txtSearchByName Is Nothing Then
gvAnnexations.DataSource =
abll.GetAnnexationsByName(txtSearchByName.Text)
gvAnnexations.DataSourceID = Nothing
gvAnnexations.DataBind()
End If
End Sub

However, it doesn't even break into this routine on the first click
(breakpoint is on the If statement). What the heck? Sometimes it works and
sometimes it doesn't. Is this some kind of ASP.NET (2.0) bug or something?

S
 
G

Guest

Public Sub btnSearchByName_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim abll As New AnnexationsBLL
If Not txtSearchByName Is Nothing Then
gvAnnexations.DataSource =
abll.GetAnnexationsByName(txtSearchByName.Text)
gvAnnexations.DataSourceID = Nothing
gvAnnexations.DataBind()
End If
End Sub

However, it doesn't even break into this routine on the first click
(breakpoint is on the If statement). What the heck? Sometimes it works and
sometimes it doesn't. Is this some kind of ASP.NET (2.0) bug or something?

hmm, try to set EnableViewState to true, maybe this can change that?
 
G

Guest

Yep, already tried that and it doesn't seem to have any effect.

Well, I don't see any error here. I think you have a validation
controls and/or a client script that makes this strange effect. If you
cannot find an error, send a full code of your webform, I will try to
look into it.
 
S

SAL

Alexey,
if you are still listening to this thread,
I've found an interesting effect. If I tab out of the text box, the field
that is used to limit results by the button click event, the page refreshes
and in that circumstance, the button click event fires and limits the
results on the first click. I don't really get why this is happening.
This page that we've been discussing is using a master page, if that
matters, and I set the AutoEventWireup to true prior to this little effect.

S
 
G

Guest

Alexey,
if you are still listening to this thread,
I've found an interesting effect. If I tab out of the text box, the field
that is used to limit results by the button click event, the page refreshes
and in that circumstance, the button click event fires and limits the
results on the first click. I don't really get why this is happening.
This page that we've been discussing is using a master page, if that
matters, and I set the AutoEventWireup to true prior to this little effect.

Try make a copy of the form, remove all controls except the one which
failed and see if it helps. There is something that affects on it.
 
S

SAL

Well, I did that and it seems to be working as expected now. I had a label
control on the page with an ID="lblSearchByName"
and the textbox's ID="txtSearchByName"
It's hard to believe it would get confused by this but maybe.

So now, the textbox is behaving more as one would expect. When I start to
type in a name, it shows previously typed in names that begin with the
letters I'm typing. It wasn't doing that before. Also, when I tab out of the
textbox, the page does not refresh as it should not.

Thank you very much for your help.
S
 
K

kinh.bui

Well, I did that and it seems to be working as expected now. I had a label
control on the page with an ID="lblSearchByName"
and the textbox's ID="txtSearchByName"
It's hard to believe it would get confused by this but maybe.

So now, the textbox is behaving more as one would expect. When I start to
type in a name, it shows previously typed in names that begin with the
letters I'm typing. It wasn't doing that before. Also, when I tab out of the
textbox, the page does not refresh as it should not.

Thank you very much for your help.
S

Hi guys,
I have the same issue here where the link button only fires after the
sencond click. I try to follow you guys reply above and not sure if I
follow you guys. can you guys help me out again by stepping me
through?
Any help is greatly appreciated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top