Inside my boxLang_OnSelectedIndexChanged() event I got this :-
if (txtbox1.Text != "" && txtbox2.Text != "")
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "confirm('Changing the language will clear the text in the textboxes. Click OK to proceed.');", true);
txtbox1.Text = "";
txtbox2.Text = "";
}
Now what is happening is that. When I select a different item from the drop down list this confirm box does show up BUT it first clears the content of the text boxes and then this confirm box appears. What I want is that the textboxes content should be cleared ONLY when OK is clicked.
What am I doing wrong? Please help.Thanks.
edit @jgauffin ** I typed return where you have. Now what is happening is that its just clearing the textboxes right away..didn't even show the confirm box this time! Whats wrong now?? Please reply..thnx**
edit 2 I tried as follows:-
Inside my BindDropDown() method I added :-
dropdownbox1.Attributes.Add("onChange","DisplayConfirmation()");
then in my aspx page I have added the following script as follows:-
<script type="css/javascript">
function DisplayConfirmation() {
if (confirm('Changing the language will clear the text in the textboxes. Click OK to proceed.')) {
__doPostback('dropdownbox1','');
}
}
</script>
This function is not getting called when drop down's selected index is changed. What's wrong?
edit 3:- ok I changed the line of code as follows:-
dropdownbox1.Attributes.Add("onchange", "javascript:return DisplayConfirmation()");
Still wont work. I am new to JavaScript and all so having problems. Help will be much appreciated.
Inside my boxLang_OnSelectedIndexChanged() event I got this :-
if (txtbox1.Text != "" && txtbox2.Text != "")
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "confirm('Changing the language will clear the text in the textboxes. Click OK to proceed.');", true);
txtbox1.Text = "";
txtbox2.Text = "";
}
Now what is happening is that. When I select a different item from the drop down list this confirm box does show up BUT it first clears the content of the text boxes and then this confirm box appears. What I want is that the textboxes content should be cleared ONLY when OK is clicked.
What am I doing wrong? Please help.Thanks.
edit @jgauffin ** I typed return where you have. Now what is happening is that its just clearing the textboxes right away..didn't even show the confirm box this time! Whats wrong now?? Please reply..thnx**
edit 2 I tried as follows:-
Inside my BindDropDown() method I added :-
dropdownbox1.Attributes.Add("onChange","DisplayConfirmation()");
then in my aspx page I have added the following script as follows:-
<script type="css/javascript">
function DisplayConfirmation() {
if (confirm('Changing the language will clear the text in the textboxes. Click OK to proceed.')) {
__doPostback('dropdownbox1','');
}
}
</script>
This function is not getting called when drop down's selected index is changed. What's wrong?
edit 3:- ok I changed the line of code as follows:-
dropdownbox1.Attributes.Add("onchange", "javascript:return DisplayConfirmation()");
Still wont work. I am new to JavaScript and all so having problems. Help will be much appreciated.
Share Improve this question edited Jan 21, 2011 at 4:44 Serenity asked Jan 20, 2011 at 13:29 SerenitySerenity 5,09820 gold badges70 silver badges104 bronze badges 1- Typed Editor by mistake..have editted it..sorry – Serenity Commented Jan 20, 2011 at 13:34
2 Answers
Reset to default 3ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "return confirm('Changing the language will clear the text in the textboxes. Click OK to proceed.');", true);
return is needed to break the process on cancel.
That's not going to work. You're posting back to the server, then registering the javascript confirm code, and then clearing content. The javascript confirm box will only actually appear once the page has reloaded, by which time you've already cleared the textbox values. It's like you're confusing clientside and server side programming. Client side code like javascript will only execute when the server has finished doing it's thing and the page is loaded.
What you need is this answer, probably:
DropdownList autoposback after client confirmation
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742361957a4429565.html
评论列表(0条)