srafi78
asked on
Javascript ConfirmBox in ASP.NET 1.1
Currently I am using a java script alert box in the button command of the datagrid, like after button is clicked I am checking for a condition and if satisfied alerting the user with the alert box and then update the database.
Now what the user wants is a confirm box and when he selects yes the DB should be updated and no should exit the sub. How can I achieve this..
I browsed through meny websites but was not able to make out how retrieve the user input for the confirm box.
Please provide a sample to acieve this...
Thanks!
Now what the user wants is a confirm box and when he selects yes the DB should be updated and no should exit the sub. How can I achieve this..
I browsed through meny websites but was not able to make out how retrieve the user input for the confirm box.
Please provide a sample to acieve this...
Thanks!
Hi,
You will have to do something like this (Adding attributes to the web control button) in your page load event on the first time
// Adding JScript to the buttons to cause a confirmation action on the save
btnSaveChanges.Attributes. Add("OnCli ck","retur n confirm('You are about to save "
+ nRecordCount + sNumberOfRecords+" Continue? ');");
You will have to do something like this (Adding attributes to the web control button) in your page load event on the first time
// Adding JScript to the buttons to cause a confirmation action on the save
btnSaveChanges.Attributes.
+ nRecordCount + sNumberOfRecords+" Continue? ');");
ASKER
I am not able to figure out how this will be working as I want to add this functionality to a dynamically created button in the datagrid,
On clicking the button in the grid the datagrid_buttoncommand fires, how am I goin to handle the confirm box in this event?
On clicking the button in the grid the datagrid_buttoncommand fires, how am I goin to handle the confirm box in this event?
ASKER
OK I am using a Farpoint web spread for displaying the data and using a ButtonCellType as the command button.
I donot see any propety of this ButtonCellType that is an "Attribute" I do not know how to achieve this...
Can I do get the result of the following function with out the onclick event...
If Not Page.IsStartupScriptRegist ered("Cfrm Msg") Then
Page.RegisterStartupScript ("CfrmMsg" , "<script language='javascript'>" & _
"var slot=confirm('Do you want to slot the item in the selected Location?');" & _
"</script>")
End If
I donot see any propety of this ButtonCellType that is an "Attribute" I do not know how to achieve this...
Can I do get the result of the following function with out the onclick event...
If Not Page.IsStartupScriptRegist
Page.RegisterStartupScript
"var slot=confirm('Do you want to slot the item in the selected Location?');" & _
"</script>")
End If
ASKER
Actually how can I capture the value returned by the confirm MessageBox from java script into my asp.net
ASKER
Can I store the value returned by the javascript function in a session variable and use it instead of the onClick event handler?
ASKER
I added ahidden field to the web form and then stored a default value in it, then based upon the user input for ok did the postback again...and it worked fine for me....
RegisterStartupScript("pop up", "<script language='javascript'> " & _
"var slot=confirm('This Location Selected does not match the Height Requirement.\n\n Click Ok to slot or Cancel to select a differnt location.');" & _
"if (slot){document.Form1.hidd enFlag.val ue='True'; __doPostBa ck('" & EventTarget & "','" & EventArgument & "');}else{document.Form1.h iddenFlag. value='Fal se';}</scr ipt>")
RegisterStartupScript("pop
"var slot=confirm('This Location Selected does not match the Height Requirement.\n\n Click Ok to slot or Cancel to select a differnt location.');" & _
"if (slot){document.Form1.hidd
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
function Afunction(someArguments, moreArguments)
{
if(window.confirm("Update the DB?\n\nClick OK to update or CANCEL"))
{
// add logic to perform the update
// possible a redirect or simply a return true
}
}