469,943 Members | 2,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,943 developers. It's quick & easy.

determine if textbox is cleared

I have a textbox were users can enter data, then they can delete it all and enter in new data again and click submit. Is there a way to determine if the user deleted the text they entered in? I'm storing the data in a Varailble for further use and if they delete the text my varialble is keeping the old data entered plus adding the new data, I only want the new data they enter.

text = "Sue, Dave, Tom"

the user deletes "Sue, Dave, Tom"

and then enters "Greg, Chuck, Michelle"

so I only want to use "Greg, Chuck, Michelle", is there a way to determine if the firstnames entered got deleted?

Aug 13 '07 #1
6 1532
Is suggest adding a hidden field, which will act as a "dirty" flag.
Set its value through JavaScript in the client side onchange event of the textbox.

Then, read the hidden field's value in the server side code.

--

Riki
"Mike" <Mi**@community.nospam.comwrote in message news:uW**************@TK2MSFTNGP04.phx.gbl...
I have a textbox were users can enter data, then they can delete it all and enter in new data again and click submit. Is there a way to determine if the user deleted the text they entered in? I'm storing the data in a Varailble for further use and if they delete the text my varialble is keeping the old data entered plus adding the new data, I only want the new data they enter.

text = "Sue, Dave, Tom"

the user deletes "Sue, Dave, Tom"

and then enters "Greg, Chuck, Michelle"

so I only want to use "Greg, Chuck, Michelle", is there a way to determine if the firstnames entered got deleted?

Aug 13 '07 #2
I'm not sure how that would work. I'm doing something like that now so when they add the name it stays in state.

"Riki" <ri**@dontnagme.comwrote in message news:uA**************@TK2MSFTNGP02.phx.gbl...
Is suggest adding a hidden field, which will act as a "dirty" flag.
Set its value through JavaScript in the client side onchange event of the textbox.

Then, read the hidden field's value in the server side code.

--

Riki
"Mike" <Mi**@community.nospam.comwrote in message news:uW**************@TK2MSFTNGP04.phx.gbl...
I have a textbox were users can enter data, then they can delete it all and enter in new data again and click submit. Is there a way to determine if the user deleted the text they entered in? I'm storing the data in a Varailble for further use and if they delete the text my varialble is keeping the old data entered plus adding the new data, I only want the new data they enter.

text = "Sue, Dave, Tom"

the user deletes "Sue, Dave, Tom"

and then enters "Greg, Chuck, Michelle"

so I only want to use "Greg, Chuck, Michelle", is there a way to determine if the firstnames entered got deleted?

Aug 13 '07 #3
You can use the IndexOf property on a variable to see what the position is, of one string, inside another
if the IndexOf property is larger that zero- then it hasn't cleared

David Wier
http://aspnet101.com
http://iWritePro.com

"Mike" <Mi**@community.nospam.comwrote in message news:uW**************@TK2MSFTNGP04.phx.gbl...
I have a textbox were users can enter data, then they can delete it all and enter in new data again and click submit. Is there a way to determine if the user deleted the text they entered in? I'm storing the data in a Varailble for further use and if they delete the text my varialble is keeping the old data entered plus adding the new data, I only want the new data they enter.

text = "Sue, Dave, Tom"

the user deletes "Sue, Dave, Tom"

and then enters "Greg, Chuck, Michelle"

so I only want to use "Greg, Chuck, Michelle", is there a way to determine if the firstnames entered got deleted?

Aug 13 '07 #4
On Aug 13, 9:02 am, "Mike" <M...@community.nospam.comwrote:
I have a textbox were users can enter data, then they can delete it all and enter in new data again and click submit. Is there a way to determine if the user deleted the text they entered in? I'm storing the data in a Varailble for further use and if they delete the text my varialble is keeping the old data entered plus adding the new data, I only want the new data they enter.

text = "Sue, Dave, Tom"

the user deletes "Sue, Dave, Tom"

and then enters "Greg, Chuck, Michelle"

so I only want to use "Greg, Chuck, Michelle", is there a way to determine if the firstnames entered got deleted?
I am not sure if I am understanding the question correctly.. but
anyways I will give my input :-)

Do you want to do this check on client site or server site? On server
site it will be it will be easy since you have stored old values in
variable so just check if new text is part of old saved string.
Also your old string will be wiped out during the postback if you
don't save it in viewstate.
... something like
in Page Load do this..
this.ViewState["oldString"] = "Sue, Dave, Tom";

In Submit button etc
if (!oldString.Contains(UserTextBox.Text))
{
this.ViewState["oldString"] +=UserTextBox.Text;
}

On Client site you will need javascript

Aug 13 '07 #5
On Aug 13, 10:18 am, "newsgrou...@gmail.com" <newsgrou...@gmail.com>
wrote:
On Aug 13, 9:02 am, "Mike" <M...@community.nospam.comwrote:
I have a textbox were users can enter data, then they can delete it all and enter in new data again and click submit. Is there a way to determine if the user deleted the text they entered in? I'm storing the data in a Varailble for further use and if they delete the text my varialble is keeping the old data entered plus adding the new data, I only want the new data they enter.
text = "Sue, Dave, Tom"
the user deletes "Sue, Dave, Tom"
and then enters "Greg, Chuck, Michelle"
so I only want to use "Greg, Chuck, Michelle", is there a way to determine if the firstnames entered got deleted?

I am not sure if I am understanding the question correctly.. but
anyways I will give my input :-)

Do you want to do this check on client site or server site? On server
site it will be it will be easy since you have stored old values in
variable so just check if new text is part of old saved string.
Also your old string will be wiped out during the postback if you
don't save it in viewstate.
.. something like
in Page Load do this..
this.ViewState["oldString"] = "Sue, Dave, Tom";
typo in old code corrected below.
In Submit button etc
if (!this.ViewState["oldString"] .Contains(UserTextBox.Text))
{
this.ViewState["oldString"] +=UserTextBox.Text;

}

On Client site you will need javascript

Aug 13 '07 #6
I need it on the client side but I need to clear out the server side
variable if the textbox is deleted (empty)
<ne*********@gmail.comwrote in message
news:11**********************@x40g2000prg.googlegr oups.com...
On Aug 13, 9:02 am, "Mike" <M...@community.nospam.comwrote:
>I have a textbox were users can enter data, then they can delete it all
and enter in new data again and click submit. Is there a way to determine
if the user deleted the text they entered in? I'm storing the data in a
Varailble for further use and if they delete the text my varialble is
keeping the old data entered plus adding the new data, I only want the
new data they enter.

text = "Sue, Dave, Tom"

the user deletes "Sue, Dave, Tom"

and then enters "Greg, Chuck, Michelle"

so I only want to use "Greg, Chuck, Michelle", is there a way to
determine if the firstnames entered got deleted?

I am not sure if I am understanding the question correctly.. but
anyways I will give my input :-)

Do you want to do this check on client site or server site? On server
site it will be it will be easy since you have stored old values in
variable so just check if new text is part of old saved string.
Also your old string will be wiped out during the postback if you
don't save it in viewstate.
.. something like
in Page Load do this..
this.ViewState["oldString"] = "Sue, Dave, Tom";

In Submit button etc
if (!oldString.Contains(UserTextBox.Text))
{
this.ViewState["oldString"] +=UserTextBox.Text;
}

On Client site you will need javascript

Aug 13 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Tom McLaughlin | last post: by
7 posts views Thread by Doru Roman | last post: by
3 posts views Thread by murugavelmsc | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.