Auto Postback Handling in controls

H

HeavyMetal

Having trouble handling postbacks when they are coming from an
asp:textbox auto postback and/or a button click. Is there a way to
distiguish between the two?

Details:

...Auto postback comes from a text box when user tabs off the box
(AutoPostback="True"). this text box exists on an ascx page. this
causes a recalculation of the page. Atlas is being used.

...there is a save button on the aspx (aspx hold 2 separate controls).
if the user does not tab off the box, but wants to save the page, the
postback from the text box is run first. this causes the user to click
the save button twice; the second click actually fires the click event
which is captured.

...i have tried various option including callback functions onkeyup to
recalc the page, but the Atlas appears to interfere

...i need to prevent this double-click on the save button.

Any advise will be appreciated. Thanks.
 
H

HeavyMetal

Thanks, but your answer does not quite cover it.

i need the autopostback to re-calculate numbers on the page. then the
user has the option of clicking save.

any other thoughts?
 
A

Alessandro Zifiglio

quoting what you had stated earlier in your post : "if the user does not tab
off the box, but wants to save the page, the postback from the text box is
run first. this causes the user to click the save button twice; the second
click actually fires the click event which is captured."

This is happening because the textbox loses focus and if the text in the
textbox has changed then the textbox postsback, even though your user has
clicked on a submit button. The postback of your submit button executes the
second time because this time the text in your textbox has not changed and
wont fire, allowing your button to postback. If you want to distinguish
between the two, you can try and check __eventTarget in your requests form
collection. This should contain the id of textbox that is posting back, if
its empty then you know its not your textbox posting back but your button :

If you need to know what submit button posted back then you can do the same
check in the forms collection but instead of checking __eventTarget, pass
the id of the submit button whom you want to check for postback. If this
control did not postback then this will return empty coz only the submit
button that posted back will be available in the forms collection.

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
// this should contain the id of your textbox that is posting
back
// You can use this with textbox, linkbutton, dropdownlist etc.
string eventTarget = this.Request.Form["__eventTarget"];
if (!string.IsNullOrEmpty(eventTarget))
Response.Write(eventTarget);
}
}
 
H

HeavyMetal

Thanks for all the info - still not working, but more clear as to what
is happening.

if the user simply enters something into the textbox, does not tab off
textbox (does not lose focus), then clicks submit, the postback event
for the textbox fires because then the textbox loses focus. so, the
__EVENTTARGET target is still the textbox, even if the submit is
clicked.

I have tried to use the CallBack event handler to do the recalculation
portion, but think that it is conflicting with the Atlas i have on the
page. If you have any other thoughts, that would be great. If not,
thanks for the help.

Alessandro said:
quoting what you had stated earlier in your post : "if the user does not tab
off the box, but wants to save the page, the postback from the text box is
run first. this causes the user to click the save button twice; the second
click actually fires the click event which is captured."

This is happening because the textbox loses focus and if the text in the
textbox has changed then the textbox postsback, even though your user has
clicked on a submit button. The postback of your submit button executes the
second time because this time the text in your textbox has not changed and
wont fire, allowing your button to postback. If you want to distinguish
between the two, you can try and check __eventTarget in your requests form
collection. This should contain the id of textbox that is posting back, if
its empty then you know its not your textbox posting back but your button :

If you need to know what submit button posted back then you can do the same
check in the forms collection but instead of checking __eventTarget, pass
the id of the submit button whom you want to check for postback. If this
control did not postback then this will return empty coz only the submit
button that posted back will be available in the forms collection.

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
// this should contain the id of your textbox that is posting
back
// You can use this with textbox, linkbutton, dropdownlist etc.
string eventTarget = this.Request.Form["__eventTarget"];
if (!string.IsNullOrEmpty(eventTarget))
Response.Write(eventTarget);
}
}
HeavyMetal said:
Thanks, but your answer does not quite cover it.

i need the autopostback to re-calculate numbers on the page. then the
user has the option of clicking save.

any other thoughts?
 
A

Alessandro Zifiglio

hi, i'm afraid i dont have an out of the box solution to your problem. I can
only try and use some creativity, which might look a bit dirty, but it does
the job well. I dont think you can find a more elegant solution to this
problem. =P

what i am doing in the following 2 lines of js code is disabling the
postback on the textbox if the user did not tab out of the textbox or hit
enter. So it wont fire when the textbox loses focus. Also as you can see, i
have hijacked the className property of the textbox(input element). If you
are using a class name on your textbox you can try and exchange className
with the 'title' property.

if (!this.IsPostBack)
{
this.TextBox1.Attributes.Add("onkeydown", "if (event.keyCode ==
09 || event.keyCode == 13) this.className = 'postback';");
this.TextBox1.Attributes.Add("onchange", "if (this.className !=
'postback') return false; else this.className = '';");
}


good luck.
Regards,

Alessandro Zifiglio
http://www.AsyncUI.net

HeavyMetal said:
Thanks for all the info - still not working, but more clear as to what
is happening.

if the user simply enters something into the textbox, does not tab off
textbox (does not lose focus), then clicks submit, the postback event
for the textbox fires because then the textbox loses focus. so, the
__EVENTTARGET target is still the textbox, even if the submit is
clicked.

I have tried to use the CallBack event handler to do the recalculation
portion, but think that it is conflicting with the Atlas i have on the
page. If you have any other thoughts, that would be great. If not,
thanks for the help.

Alessandro said:
quoting what you had stated earlier in your post : "if the user does not
tab
off the box, but wants to save the page, the postback from the text box
is
run first. this causes the user to click the save button twice; the
second
click actually fires the click event which is captured."

This is happening because the textbox loses focus and if the text in the
textbox has changed then the textbox postsback, even though your user has
clicked on a submit button. The postback of your submit button executes
the
second time because this time the text in your textbox has not changed
and
wont fire, allowing your button to postback. If you want to distinguish
between the two, you can try and check __eventTarget in your requests
form
collection. This should contain the id of textbox that is posting back,
if
its empty then you know its not your textbox posting back but your button
:

If you need to know what submit button posted back then you can do the
same
check in the forms collection but instead of checking __eventTarget, pass
the id of the submit button whom you want to check for postback. If this
control did not postback then this will return empty coz only the submit
button that posted back will be available in the forms collection.

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
// this should contain the id of your textbox that is posting
back
// You can use this with textbox, linkbutton, dropdownlist
etc.
string eventTarget = this.Request.Form["__eventTarget"];
if (!string.IsNullOrEmpty(eventTarget))
Response.Write(eventTarget);
}
}
HeavyMetal said:
Thanks, but your answer does not quite cover it.

i need the autopostback to re-calculate numbers on the page. then the
user has the option of clicking save.

any other thoughts?

Alessandro Zifiglio wrote:
hi, just noticed your post. This will explain why you are probably
facing
that particular problem.

http://groups.google.com/group/micr...d+submit+button&rnum=1&hl=en#be9a7dba9ed1f80e

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net


"HeavyMetal" <[email protected]> ha scritto nel messaggio
Having trouble handling postbacks when they are coming from an
asp:textbox auto postback and/or a button click. Is there a way to
distiguish between the two?

Details:

..Auto postback comes from a text box when user tabs off the box
(AutoPostback="True"). this text box exists on an ascx page. this
causes a recalculation of the page. Atlas is being used.

..there is a save button on the aspx (aspx hold 2 separate
controls).
if the user does not tab off the box, but wants to save the page,
the
postback from the text box is run first. this causes the user to
click
the save button twice; the second click actually fires the click
event
which is captured.

..i have tried various option including callback functions onkeyup
to
recalc the page, but the Atlas appears to interfere

..i need to prevent this double-click on the save button.

Any advise will be appreciated. Thanks.
 
H

HeavyMetal

That helped - pointed me in the right direction.

i am using VB, so in the asp textbox i used the 2 attributes below. i
did this because the textbox actually resides in a gridview. this
allows the tab to do a postback and recalculate the page. it also
allows the Save button to do its own postback.

onkeydown="if (event.keyCode == 9 || event.keyCode == 13)
this.className = 'postback';"
onchange="if (this.className != 'postback') {return false;} else
{this.className = ''; __doPostBack(this);}"

thanks for all your info. problem solved.


Alessandro said:
hi, i'm afraid i dont have an out of the box solution to your problem. I can
only try and use some creativity, which might look a bit dirty, but it does
the job well. I dont think you can find a more elegant solution to this
problem. =P

what i am doing in the following 2 lines of js code is disabling the
postback on the textbox if the user did not tab out of the textbox or hit
enter. So it wont fire when the textbox loses focus. Also as you can see, i
have hijacked the className property of the textbox(input element). If you
are using a class name on your textbox you can try and exchange className
with the 'title' property.

if (!this.IsPostBack)
{
this.TextBox1.Attributes.Add("onkeydown", "if (event.keyCode ==
09 || event.keyCode == 13) this.className = 'postback';");
this.TextBox1.Attributes.Add("onchange", "if (this.className !=
'postback') return false; else this.className = '';");
}


good luck.
Regards,

Alessandro Zifiglio
http://www.AsyncUI.net

HeavyMetal said:
Thanks for all the info - still not working, but more clear as to what
is happening.

if the user simply enters something into the textbox, does not tab off
textbox (does not lose focus), then clicks submit, the postback event
for the textbox fires because then the textbox loses focus. so, the
__EVENTTARGET target is still the textbox, even if the submit is
clicked.

I have tried to use the CallBack event handler to do the recalculation
portion, but think that it is conflicting with the Atlas i have on the
page. If you have any other thoughts, that would be great. If not,
thanks for the help.

Alessandro said:
quoting what you had stated earlier in your post : "if the user does not
tab
off the box, but wants to save the page, the postback from the text box
is
run first. this causes the user to click the save button twice; the
second
click actually fires the click event which is captured."

This is happening because the textbox loses focus and if the text in the
textbox has changed then the textbox postsback, even though your user has
clicked on a submit button. The postback of your submit button executes
the
second time because this time the text in your textbox has not changed
and
wont fire, allowing your button to postback. If you want to distinguish
between the two, you can try and check __eventTarget in your requests
form
collection. This should contain the id of textbox that is posting back,
if
its empty then you know its not your textbox posting back but your button
:

If you need to know what submit button posted back then you can do the
same
check in the forms collection but instead of checking __eventTarget, pass
the id of the submit button whom you want to check for postback. If this
control did not postback then this will return empty coz only the submit
button that posted back will be available in the forms collection.

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
// this should contain the id of your textbox that is posting
back
// You can use this with textbox, linkbutton, dropdownlist
etc.
string eventTarget = this.Request.Form["__eventTarget"];
if (!string.IsNullOrEmpty(eventTarget))
Response.Write(eventTarget);
}
}
"HeavyMetal" <[email protected]> ha scritto nel messaggio
Thanks, but your answer does not quite cover it.

i need the autopostback to re-calculate numbers on the page. then the
user has the option of clicking save.

any other thoughts?

Alessandro Zifiglio wrote:
hi, just noticed your post. This will explain why you are probably
facing
that particular problem.

http://groups.google.com/group/micr...d+submit+button&rnum=1&hl=en#be9a7dba9ed1f80e

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net


"HeavyMetal" <[email protected]> ha scritto nel messaggio
Having trouble handling postbacks when they are coming from an
asp:textbox auto postback and/or a button click. Is there a way to
distiguish between the two?

Details:

..Auto postback comes from a text box when user tabs off the box
(AutoPostback="True"). this text box exists on an ascx page. this
causes a recalculation of the page. Atlas is being used.

..there is a save button on the aspx (aspx hold 2 separate
controls).
if the user does not tab off the box, but wants to save the page,
the
postback from the text box is run first. this causes the user to
click
the save button twice; the second click actually fires the click
event
which is captured.

..i have tried various option including callback functions onkeyup
to
recalc the page, but the Atlas appears to interfere

..i need to prevent this double-click on the save button.

Any advise will be appreciated. Thanks.
 
A

Alessandro Zifiglio

You are welcome.

Have a good day,
Alessandro Zifiglio
http://www.AsyncUI.net


HeavyMetal said:
That helped - pointed me in the right direction.

i am using VB, so in the asp textbox i used the 2 attributes below. i
did this because the textbox actually resides in a gridview. this
allows the tab to do a postback and recalculate the page. it also
allows the Save button to do its own postback.

onkeydown="if (event.keyCode == 9 || event.keyCode == 13)
this.className = 'postback';"
onchange="if (this.className != 'postback') {return false;} else
{this.className = ''; __doPostBack(this);}"

thanks for all your info. problem solved.


Alessandro said:
hi, i'm afraid i dont have an out of the box solution to your problem. I
can
only try and use some creativity, which might look a bit dirty, but it
does
the job well. I dont think you can find a more elegant solution to this
problem. =P

what i am doing in the following 2 lines of js code is disabling the
postback on the textbox if the user did not tab out of the textbox or hit
enter. So it wont fire when the textbox loses focus. Also as you can see,
i
have hijacked the className property of the textbox(input element). If
you
are using a class name on your textbox you can try and exchange className
with the 'title' property.

if (!this.IsPostBack)
{
this.TextBox1.Attributes.Add("onkeydown", "if (event.keyCode
==
09 || event.keyCode == 13) this.className = 'postback';");
this.TextBox1.Attributes.Add("onchange", "if (this.className
!=
'postback') return false; else this.className = '';");
}


good luck.
Regards,

Alessandro Zifiglio
http://www.AsyncUI.net

HeavyMetal said:
Thanks for all the info - still not working, but more clear as to what
is happening.

if the user simply enters something into the textbox, does not tab off
textbox (does not lose focus), then clicks submit, the postback event
for the textbox fires because then the textbox loses focus. so, the
__EVENTTARGET target is still the textbox, even if the submit is
clicked.

I have tried to use the CallBack event handler to do the recalculation
portion, but think that it is conflicting with the Atlas i have on the
page. If you have any other thoughts, that would be great. If not,
thanks for the help.

Alessandro Zifiglio wrote:
quoting what you had stated earlier in your post : "if the user does
not
tab
off the box, but wants to save the page, the postback from the text
box
is
run first. this causes the user to click the save button twice; the
second
click actually fires the click event which is captured."

This is happening because the textbox loses focus and if the text in
the
textbox has changed then the textbox postsback, even though your user
has
clicked on a submit button. The postback of your submit button
executes
the
second time because this time the text in your textbox has not changed
and
wont fire, allowing your button to postback. If you want to
distinguish
between the two, you can try and check __eventTarget in your requests
form
collection. This should contain the id of textbox that is posting
back,
if
its empty then you know its not your textbox posting back but your
button
:

If you need to know what submit button posted back then you can do the
same
check in the forms collection but instead of checking __eventTarget,
pass
the id of the submit button whom you want to check for postback. If
this
control did not postback then this will return empty coz only the
submit
button that posted back will be available in the forms collection.

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
// this should contain the id of your textbox that is
posting
back
// You can use this with textbox, linkbutton, dropdownlist
etc.
string eventTarget = this.Request.Form["__eventTarget"];
if (!string.IsNullOrEmpty(eventTarget))
Response.Write(eventTarget);
}
}
"HeavyMetal" <[email protected]> ha scritto nel messaggio
Thanks, but your answer does not quite cover it.

i need the autopostback to re-calculate numbers on the page. then
the
user has the option of clicking save.

any other thoughts?

Alessandro Zifiglio wrote:
hi, just noticed your post. This will explain why you are probably
facing
that particular problem.

http://groups.google.com/group/micr...d+submit+button&rnum=1&hl=en#be9a7dba9ed1f80e

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net


"HeavyMetal" <[email protected]> ha scritto nel messaggio
Having trouble handling postbacks when they are coming from an
asp:textbox auto postback and/or a button click. Is there a way
to
distiguish between the two?

Details:

..Auto postback comes from a text box when user tabs off the box
(AutoPostback="True"). this text box exists on an ascx page. this
causes a recalculation of the page. Atlas is being used.

..there is a save button on the aspx (aspx hold 2 separate
controls).
if the user does not tab off the box, but wants to save the page,
the
postback from the text box is run first. this causes the user to
click
the save button twice; the second click actually fires the click
event
which is captured.

..i have tried various option including callback functions
onkeyup
to
recalc the page, but the Atlas appears to interfere

..i need to prevent this double-click on the save button.

Any advise will be appreciated. Thanks.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top