Click to See Complete Forum and Search --> : avoid getting save confirmation on button click


sansircar
January 30th, 2006, 03:46 PM
I have a search button on my web page, which is supposed to save the contents of the page into the database before it does the search.
Before i save the contents i get a confirmation from the user -- for which i'm using the following code -

btnSearch.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to save')") ;
my problem is that, i do not want the above confirmation message to appear, when the user clicks the Search button
for the first time, as there's nothing to save at that moment, and rather execute the search code.
Please advise.

HairyMonkeyMan
January 30th, 2006, 06:30 PM
There are probably a few things you could do here.

1. A bit crude. (in page load routine)
If PostBack Then
btnSearch.Attributes.Clear
btnSearch.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to save')")
End If

2. Better way.
' In your button's click event
ViewState("GotResults") = True

' In page load event
If Not PostBack Then
ViewState("GotResults") = False
Else
If ViewState("GotReults") Then
btnSearch.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to save')")
End If
End If


Enjoy