ASP.Net Postback event eats button click event | | |
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 | | | | re: ASP.Net Postback event eats button click event
> Private Sub TextBox1_TextChanged(ByVal sender As System.Object,[color=blue]
> 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.[/color]
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 | | | | re: ASP.Net Postback event eats button click event
Mark Lingen wrote:[color=blue]
> 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[/color]
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 | | | | re: ASP.Net Postback event eats button click event
"Jos" <josnospambranders@fastmail.fm> wrote in message news:<uGYJuSFfEHA.1424@tk2msftngp13.phx.gbl>...[color=blue]
> Mark Lingen wrote:[color=green]
> > 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[/color]
>
> 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?[/color]
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 | | | | re: ASP.Net Postback event eats button click event
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:
[color=blue]
> "Jos" <josnospambranders@fastmail.fm> wrote in message news:<uGYJuSFfEHA.1424@tk2msftngp13.phx.gbl>...[color=green]
> > Mark Lingen wrote:[color=darkred]
> > > 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[/color]
> >
> > 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?[/color]
>
> 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
>[/color] |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|