Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding javascript alert box to CommandField in gridview

Status
Not open for further replies.

zerkat

Programmer
Jul 12, 2007
103
US
We have an editable gridview in an accounting app. In order to show the edit/update/cancel buttons we are using <asp:CommandField ShowEditButton="true">. We need to add an alert/message box when a user tries to put in an entry that is invalid. How do we add an alert to a CommandField?

*we can not convert the commandField into a linkButton
 
Read this thread on how to reference the button:

thread855-1523424

Then just use .Attribues.Add to add the javascript alert.
 
I can get this to work on every edit button but I only want it to execute on the RowUpdating for the gridview. I tried putting the call to the function in the RowUpdating but then it won't execute.

I would think that this needs to be called in the RowUpdating since I only want the alert to display after a user clicks update. This is the code that I had for the function when I had it in the RowUpdating:

Public Shared Sub UpdateCommand(ByRef gv As GridView, Byval e as GridViewUpdateEventArgs)

If gv.SelectedRow.RowType = DataControlRowType.DataRow Then
For Each dcf As DataControlField in gv.Columns
if dcf.ToString = "CommandField" Then
If CTYPE(dcf, CommandField).ShowEditButton = True Then
gv.Rows.Item(gv.Columns.IndexOf(dcf).Attributes.Add("onclick", return confirm('alert message')")
End if
end if
Next
end if

End sub



 
what is the reference for the update button?
 
I don't know, I don't use them, I use template columns with buttons in them
 
ugh - this would be easier if we could used actual link buttons instead of the commandField. we may have found a work around using ajax. if we get this worked out i'll post the code for anyone who wants it.
 
Ok - we just used a modalPopupExtender to popup a panel that contained a message and two buttons instead of using a javascript alert box. Then in the code behind in our If statement use the enable and show properties of the extender to display the panel when the update button was clicked. Since the panel with the message had two buttons we created events to handle each click event for each button and passed through the appropriate parameters for the function that updated the record in the gridview.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top