Re: why do i have to click two times on the button?

Re: why do i have to click two times on the button?

am 18.12.2007 18:18:35 von NoSpamMgbworld

NOTE: Not specific to your problem, but shows an issue with application
setup.

If Page.IsPostBack Then

You should handle postback events in your control event handlers. Unless
every possible action you can ever add to a page does the same thing
(extremely rare), there is no need for the IsPostBack = true branch in the
Page_Load.

I would refactor this test into the button click event. If that is not
possible, then rethink the intent. If the textbox has to be visible to save
to the database, boom, there is your trouble. It is not visible until
someone does something on the page. ANd, if that is the intent, you need to
go through the process and add some validation when someone attempts to
submit via button without the box showing.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
"Theo" wrote in message
news:OBeXLjXQIHA.5016@TK2MSFTNGP06.phx.gbl...
> Hello,
>
> I want to insert values from a dropdownlist and textbox into a table. The
> textbox may be visible only if the selectedvalue of the ddl is "2".
> My problem is that i need to click two times on the button before the
> values are inserted in the table. I put a response.write to check the
> value: after the first click, nothing appears, after the second, they
> appear and are inserted.
>
> Why is that?
> Thanks
> Theo
>
>
>
>
>

>


> > AutoPostBack=true>
>

>
> ----------------
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Me.Load
> If Page.IsPostBack Then
> If DropDownList1.SelectedValue = "2" Then
> Textbox1.visible = True
> End If
> End if
> End sub
> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> Dim ddl1, tb1 As String
> ddl1 = DropDownList1.SelectedValue
> tb1 = TextBox1.Text
> Response.Write(ddl1 & " " & tb1)
> myclass.save(ddl1,tb1)
> End Sub
>

Re: why do i have to click two times on the button?

am 19.12.2007 00:00:24 von Latish Sehgal

Why do you have AutoPostBack set to "True" in your textbox?
That causes the postback to happen everytime the text changes in your
textbox and it loses focus. So what's actually happening here is that
when you press the button, instead of the button handler being fired,
its the autopostback event from textbox.
And when you press the button again (if you do not change text), then
the button handler executes and saves your data.
Removing AutoPostBack=true from your textbox should fix this.

If however, you do want Autopostback to be true for your textbox, you
should create another textbox or some control there, so that when you
click on the new textbox, the autopostback event will fire then and
not block your button event handler.

-Latish Sehgal
http://www.dotnetsurfers.com/

Re: why do i have to click two times on the button?

am 19.12.2007 17:11:09 von NoSpamMgbworld

I did not notice that in the OPs code, but that is a good point. It also
causes the If PostBack = True Then to fire every single time you update a
textbox, which kicks you into an interesting loop, albeit one that requires
user interaction. :-)

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
"Latish Sehgal" wrote in message
news:7d32af41-8079-436d-8874-b9ed6e018f0e@d21g2000prf.google groups.com...
> Why do you have AutoPostBack set to "True" in your textbox?
> That causes the postback to happen everytime the text changes in your
> textbox and it loses focus. So what's actually happening here is that
> when you press the button, instead of the button handler being fired,
> its the autopostback event from textbox.
> And when you press the button again (if you do not change text), then
> the button handler executes and saves your data.
> Removing AutoPostBack=true from your textbox should fix this.
>
> If however, you do want Autopostback to be true for your textbox, you
> should create another textbox or some control there, so that when you
> click on the new textbox, the autopostback event will fire then and
> not block your button event handler.
>
> -Latish Sehgal
> http://www.dotnetsurfers.com/

Re: why do i have to click two times on the button?

am 22.12.2007 15:46:27 von Theo

Thanks

"Cowboy (Gregory A. Beamer)" schreef in
bericht news:O5e2InlQIHA.5288@TK2MSFTNGP04.phx.gbl...
>I did not notice that in the OPs code, but that is a good point. It also
>causes the If PostBack = True Then to fire every single time you update a
>textbox, which kicks you into an interesting loop, albeit one that requires
>user interaction. :-)
>
> --
> Gregory A. Beamer
> MVP, MCP: +I, SE, SD, DBA
>
> *************************************************
> | Think outside the box! |
> *************************************************
> "Latish Sehgal" wrote in message
> news:7d32af41-8079-436d-8874-b9ed6e018f0e@d21g2000prf.google groups.com...
>> Why do you have AutoPostBack set to "True" in your textbox?
>> That causes the postback to happen everytime the text changes in your
>> textbox and it loses focus. So what's actually happening here is that
>> when you press the button, instead of the button handler being fired,
>> its the autopostback event from textbox.
>> And when you press the button again (if you do not change text), then
>> the button handler executes and saves your data.
>> Removing AutoPostBack=true from your textbox should fix this.
>>
>> If however, you do want Autopostback to be true for your textbox, you
>> should create another textbox or some control there, so that when you
>> click on the new textbox, the autopostback event will fire then and
>> not block your button event handler.
>>
>> -Latish Sehgal
>> http://www.dotnetsurfers.com/
>
>

Re: why do i have to click two times on the button?

am 23.12.2007 06:43:15 von gnewsgroup

On Dec 18, 12:18 pm, "Cowboy \(Gregory A. Beamer\)"
wrote:
> NOTE: Not specific to your problem, but shows an issue with application
> setup.
>
> If Page.IsPostBack Then
>
> You should handle postback events in your control event handlers. Unless
> every possible action you can ever add to a page does the same thing
> (extremely rare), there is no need for the IsPostBack = true branch in the
> Page_Load.
>
> I would refactor this test into the button click event. If that is not
> possible, then rethink the intent. If the textbox has to be visible to save
> to the database, boom, there is your trouble. It is not visible until
> someone does something on the page. ANd, if that is the intent, you need to
> go through the process and add some validation when someone attempts to
> submit via button without the box showing.
>
> --
> Gregory A. Beamer
> MVP, MCP: +I, SE, SD, DBA
>
> *************************************************
> | Think outside the box!
> |
> *************************************************"Theo" wrote in message
>
> news:OBeXLjXQIHA.5016@TK2MSFTNGP06.phx.gbl...
>
> > Hello,
>
> > I want to insert values from a dropdownlist and textbox into a table. The
> > textbox may be visible only if the selectedvalue of the ddl is "2".
> > My problem is that i need to click two times on the button before the
> > values are inserted in the table. I put a response.write to check the
> > value: after the first click, nothing appears, after the second, they
> > appear and are inserted.
>
> > Why is that?
> > Thanks
> > Theo
>
> >
> >
> >
> >

> >


> > > > AutoPostBack=true>
> >

> >
> > ----------------
> > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> > System.EventArgs) Handles Me.Load
> > If Page.IsPostBack Then
> > If DropDownList1.SelectedValue = "2" Then
> > Textbox1.visible = True
> > End If
> > End if
> > End sub
> > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
> > System.EventArgs) Handles Button1.Click
> > Dim ddl1, tb1 As String
> > ddl1 = DropDownList1.SelectedValue
> > tb1 = TextBox1.Text
> > Response.Write(ddl1 & " " & tb1)
> > myclass.save(ddl1,tb1)
> > End Sub

I have always been puzzled by the same kind of problem. It's been 1
year since I noticed that if I use the UpdatePanel of the MS ajax
framework, quite often a button has to be clicked twice to cause a
postback.

I have this problem with one page in my current web application. The
button itself is not inside an UpdatePanel, I do have a few controls
with AutoPostBack=true on the page.

I haven't figured out what is causing this problem. Any idea if this
indeed has to do with the ajax framework?