473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DropDownList Confirmation

I have been struggling with this for a while, and have seen lots of
related postings, but nothing (as far as I can see) that answers this
directly.

Im using vb dotnet and have an aspx that has a drop down list. For the
selected item in the listbox a number of textboxes are populated from
the database. The user can change the data in one or more of these
text boxes, after which they should press the button that saves he
data if they want to commit those changes.

What I want to achieve is that when the user selects a different item
in the drop down, the syetm should prompt with a confirmation to ask
whether the user wishes to save the changes. If the user selects yes,
then the save is run (in the code behind) before moving to the newly
selected item in the drop down. If the user selects no then the newly
selected item is displayed with no save.

I have the code behind that does the save, populates the screen etc. I
can get a javascript confirm working, but I cant bring it all together
to achieve exactly what I am describing above.

Any help would be very gratefully received.
Nov 18 '05 #1
7 4692
Hi

<select onchange="if(confirm('Save?')) this.form.SUBMITBTNNAME.click()"
If yes it will click the submit button

Or perhaps

<select onchange="this.form.bDoSave.value = confirm('Save?');
this.form.SUBMITBTNNAME.click()"
<input type="hidden" name="bDoSave"....
Then you can check the hidden element on the server....

--
Best Regards
Vidar Petursson
==============================
Microsoft Visual: Scripting MVP 2000-2004
http://www.icysoft.com/
http://www.deus-x.com/ Instant e-commerce
http://www.microsoft.com/technet/scriptcenter/
Playground: http://213.190.104.211/ ( IE 5.5+ only )

No matter where you go there you are
==============================
"Andy" <ne*****************@hotmail.com> wrote in message
news:9e**************************@posting.google.c om...
I have been struggling with this for a while, and have seen lots of
related postings, but nothing (as far as I can see) that answers this
directly.

Im using vb dotnet and have an aspx that has a drop down list. For the
selected item in the listbox a number of textboxes are populated from
the database. The user can change the data in one or more of these
text boxes, after which they should press the button that saves he
data if they want to commit those changes.

What I want to achieve is that when the user selects a different item
in the drop down, the syetm should prompt with a confirmation to ask
whether the user wishes to save the changes. If the user selects yes,
then the save is run (in the code behind) before moving to the newly
selected item in the drop down. If the user selects no then the newly
selected item is displayed with no save.

I have the code behind that does the save, populates the screen etc. I
can get a javascript confirm working, but I cant bring it all together
to achieve exactly what I am describing above.

Any help would be very gratefully received.

Nov 18 '05 #2
Hi,

If you want to have the confirmation popup only when the user change at
least one of the controls then you need to do some javascript scripting,
create a variable at page level:
var anychange = false;

then you have to add an onchange handler for ALL the controsl you want, you
can do this in the code behind using:
textbox1.Attributes.Add( "onchange" , "setchanged();")

finally in the dropdownlist you should do the same:
textbox1.Attributes.Add( "onchange" , "CheckIfChanged();")

in this function you show the confirmation if the anychange variable is
true, and submit the form if needed.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Andy" <ne*****************@hotmail.com> wrote in message
news:9e**************************@posting.google.c om...
I have been struggling with this for a while, and have seen lots of
related postings, but nothing (as far as I can see) that answers this
directly.

Im using vb dotnet and have an aspx that has a drop down list. For the
selected item in the listbox a number of textboxes are populated from
the database. The user can change the data in one or more of these
text boxes, after which they should press the button that saves he
data if they want to commit those changes.

What I want to achieve is that when the user selects a different item
in the drop down, the syetm should prompt with a confirmation to ask
whether the user wishes to save the changes. If the user selects yes,
then the save is run (in the code behind) before moving to the newly
selected item in the drop down. If the user selects no then the newly
selected item is displayed with no save.

I have the code behind that does the save, populates the screen etc. I
can get a javascript confirm working, but I cant bring it all together
to achieve exactly what I am describing above.

Any help would be very gratefully received.

Nov 18 '05 #3
Can you explain further - Im not with you

Thanks
Nov 18 '05 #4
So, the onchange event for the textbox sets the flag anychange to
true. The dropdownlist, when changed, fires the event which checks the
flag.

When testing, I took the approach that I would ask the user if they
wanted to save and triggered the following on listbox change.

<script>
function AskUser()
{
var answer = window.confirm("Do you want to save?")
document.forms(0).answer.value = String(answer)
document.forms(0).submit()
}
</script>

But I had 2 problems

1) I couldnt work out how to get the True\False from the confirm to
either save then go and get the new data for the list box item, or
just go and get the new data for the list box item (without saving).

2) At the point at which the above event fires, the list box has
already changed, and Ive lost the original listbox item, which is what
I need when running the save in the code behind.
I hope these questions are sensible and that somebody can put me out
of my misery.

:-(
Nov 18 '05 #5
Hi

Ok.. why not put the ID of item edited into a hidden input
as the dropdown will change ..

<html>
<head>
<script>
function doConfirm(f){
var bIsDirty = 0;
var e;
// You can check element type & compare defaultValue to value
// The defaultValue is what you populate on the server
// for simplicity I only check type = text/textarea
// radio/checkbox have defaultChecked which you can check also
for(i=0;i<f.elements.length;i++)
{
e = f.elements[i];
if(e.type == "text" || e.type == "textarea") if(e.defaultValue !=
e.value) bIsDirty = 1;
}
if( bIsDirty ) f.bDoSave.value = confirm("Item changed!!\n\nDo you want to
save?") ? 1 : 0;
f.submit();
// If you are using validators you can call the click method of the
submitbtn
// instead of f.submit();
// do f.mySubmitBtn.click();
}
</script>
</head>
<body>
<form>
<select onchange="doConfirm(this.form)" name="mySelect">
<option value="1">blah1</option>
<option value="2" selected>blah2</option>
</select>
<input type="hidden" name="myHiddenID" value="2"> <!-- Store ID here, same
as the selected one in the dropdown -->
<input type="hidden" name="bDoSave" value="0"> <!-- push save flag here,
default 0 -->
<input type="text" name="myInput1" value="SOMEVALUE">
<input type="text" name="myInput2" value="SOMEVALUE">
<textarea name="myTextArea">blah blah</textarea>
</form>
</body>
</html>

More info:
http://msdn.microsoft.com/library/de...ence_entry.asp

--
Best Regards
Vidar Petursson
==============================
Microsoft Visual: Scripting MVP 2000-2004
http://www.icysoft.com/
http://www.deus-x.com/ Instant e-commerce
http://www.microsoft.com/technet/scriptcenter/
Playground: http://213.190.104.211/ ( IE 5.5+ only )

No matter where you go there you are
==============================
"Andy" <ne*****************@hotmail.com> wrote in message
news:9e**************************@posting.google.c om...
So, the onchange event for the textbox sets the flag anychange to
true. The dropdownlist, when changed, fires the event which checks the
flag.

When testing, I took the approach that I would ask the user if they
wanted to save and triggered the following on listbox change.

<script>
function AskUser()
{
var answer = window.confirm("Do you want to save?")
document.forms(0).answer.value = String(answer)
document.forms(0).submit()
}
</script>

But I had 2 problems

1) I couldnt work out how to get the True\False from the confirm to
either save then go and get the new data for the list box item, or
just go and get the new data for the list box item (without saving).

2) At the point at which the above event fires, the list box has
already changed, and Ive lost the original listbox item, which is what
I need when running the save in the code behind.
I hope these questions are sensible and that somebody can put me out
of my misery.

:-(

Nov 18 '05 #6
Thanks for that - Ill give it a go !
Nov 18 '05 #7
OK

I understand the Isdirty concept !
I understand the ability to store the values in hidden fields

But how is the save in the code-behind running. Is this your
f.mySubmitBtn.click\f.submit ?

I have the save in the code_behind, and I want that to be executed
using the value in the hidden field as the key, and the other text
boxes as the data fields.

Sorry if Im being a bit thick here - but if you can explain this last
bit to me Ill be there.
Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: PK9 | last post by:
Please help: I have a DropdownList control that has a server-side onSelectedIndexChanged event handler. Before this server-side event handler is run, I'd like a client-side javascript...
3
by: David | last post by:
Hi, I have the following Javascript that fires from an onChange event for a dropdownlist. When the dropdownlist changes, it shows a dialog box with Yes and Cancel. If I press Cancel, I want the...
6
by: Nedu N | last post by:
Hi, I want to have confirmation(Yes/No) on a button of the webform in which there are many validation controls. I want all the validation controls to be triggered first and then Yes/No...
2
by: MBhat | last post by:
Hello, I have a dropdownlist server control.On selectedIndexChange I do some functionality. In addtion to this I need to check for something else. To do this I have to use javascript function to...
2
by: jason | last post by:
Pardon my ignorance on this. The below code works, except, when I edit a record and update the two drop downs take the first entry in the dropdownlist if not selected. I'd also like the dropdown to...
3
by: Sam C | last post by:
Hi, I have an ASP.Net page which has a DropDownList on it. The DDL is populated via a method which is called from the Page_Load if IsPostBack = False. When the form is submitted the...
2
by: bienwell | last post by:
Hi all, I still have a problem when using Confirmation box in ASP.NET program. I need to get the value return of YES or NO from confirmation box in Sub function of VB program to do some tasks....
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
3
by: Steve Hershoff | last post by:
Hi everyone, I'm not sure that what I'm trying can't be done (at least, not how I'm trying to do it) but I was hoping for confirmation and possible suggestions on a future approach. We have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.