By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,599 Members | 1,678 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,599 IT Pros & Developers. It's quick & easy.

ASP.Net Postback event eats button click event

P: n/a
I've found a problem with postback event handling and webcontrol
buttons. Try out the following code in an ASP.Net project and you
will see. Create a web project in VB.Net and drop this code ontop of
the webform1:

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not IsPostBack Then
Me.Label1.Text = "Start..."
Me.TextBox1.Text = ""
End If
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Me.Label1.Text &= "/Text Box Changed"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
'Response.Redirect("http://www.msn.com")
Me.Label1.Text &= "/Button Clicked"
End Sub
End Class

Results, if the user changes the textbox and then clicks the button
the buttons click event doesn't fire only the textchanged event fires.
My assumption is that both events would fire and the textchanged
event would be first.

Is there a work around to this bug?

Thanks,
Mark Lingen
ICOS Corp
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> Private Sub TextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Me.Label1.Text &= "/Text Box Changed"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
'Response.Redirect("http://www.msn.com")
Me.Label1.Text &= "/Button Clicked"
End Sub
End Class

Results, if the user changes the textbox and then clicks the button
the buttons click event doesn't fire only the textchanged event fires.
My assumption is that both events would fire and the textchanged
event would be first.


I'm no expert, but for the TextChanged handler to work, it'd need to be
triggered on the front end via javascript. Is it not doing that? Otherwise,
I'd assume the button click would only be handled by the button click
handler.

-Darrel
Nov 18 '05 #2

P: n/a
Jos
Mark Lingen wrote:
I've found a problem with postback event handling and webcontrol
buttons. Try out the following code in an ASP.Net project and you
will see. Create a web project in VB.Net and drop this code ontop of
the webform1:

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not IsPostBack Then
Me.Label1.Text = "Start..."
Me.TextBox1.Text = ""
End If
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Me.Label1.Text &= "/Text Box Changed"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
'Response.Redirect("http://www.msn.com")
Me.Label1.Text &= "/Button Clicked"
End Sub
End Class

Results, if the user changes the textbox and then clicks the button
the buttons click event doesn't fire only the textchanged event fires.
My assumption is that both events would fire and the textchanged
event would be first.

Is there a work around to this bug?

Thanks,
Mark Lingen
ICOS Corp


I tried it and it works fine.
I get:
Start.../Text Box Changed/Button Clicked

So, there is no bug.

Don't you use any other settings than the code you gave us?

--

Jos

Nov 18 '05 #3

P: n/a
"Jos" <jo***************@fastmail.fm> wrote in message news:<uG**************@tk2msftngp13.phx.gbl>...
Mark Lingen wrote:
I've found a problem with postback event handling and webcontrol
buttons. Try out the following code in an ASP.Net project and you
will see. Create a web project in VB.Net and drop this code ontop of
the webform1:

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not IsPostBack Then
Me.Label1.Text = "Start..."
Me.TextBox1.Text = ""
End If
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Me.Label1.Text &= "/Text Box Changed"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
'Response.Redirect("http://www.msn.com")
Me.Label1.Text &= "/Button Clicked"
End Sub
End Class

Results, if the user changes the textbox and then clicks the button
the buttons click event doesn't fire only the textchanged event fires.
My assumption is that both events would fire and the textchanged
event would be first.

Is there a work around to this bug?

Thanks,
Mark Lingen
ICOS Corp


I tried it and it works fine.
I get:
Start.../Text Box Changed/Button Clicked

So, there is no bug.

Don't you use any other settings than the code you gave us?


Did you leave the Focus in the text box after changing it, then click
on the button. Do you still get both events.

Thanks,
Mark
Nov 18 '05 #4

P: n/a
I have a very similar problem. Same as Mark I have page with couple of
textboxes and 2 buttons. One of textboxes has Autopostback=true. If textbox
with autopostback=true is empty and I type something into it and click using
my mouse on any of the buttons all events fire as expected Page_Load,
TextChanged, Button.Click. However if textbox is not empty - already contains
some text and I just change this text and click on the button I get only
Page_Load and Textchanged fired, no Button.Click event. Does anyone knows
what is the problem and how to
workaround it?

Thanks

"Mark Lingen" wrote:
"Jos" <jo***************@fastmail.fm> wrote in message news:<uG**************@tk2msftngp13.phx.gbl>...
Mark Lingen wrote:
I've found a problem with postback event handling and webcontrol
buttons. Try out the following code in an ASP.Net project and you
will see. Create a web project in VB.Net and drop this code ontop of
the webform1:

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not IsPostBack Then
Me.Label1.Text = "Start..."
Me.TextBox1.Text = ""
End If
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Me.Label1.Text &= "/Text Box Changed"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
'Response.Redirect("http://www.msn.com")
Me.Label1.Text &= "/Button Clicked"
End Sub
End Class

Results, if the user changes the textbox and then clicks the button
the buttons click event doesn't fire only the textchanged event fires.
My assumption is that both events would fire and the textchanged
event would be first.

Is there a work around to this bug?

Thanks,
Mark Lingen
ICOS Corp


I tried it and it works fine.
I get:
Start.../Text Box Changed/Button Clicked

So, there is no bug.

Don't you use any other settings than the code you gave us?


Did you leave the Focus in the text box after changing it, then click
on the button. Do you still get both events.

Thanks,
Mark

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.