wsyeager36
Nov 28th, 2003, 03:21 PM
I know this question has been asked several different times and ways, but even after checking out the answers to these questions and the aspalliance article on how to perform a delete confirm, I'm still having a problem and I just can't figure it out.......
All I'm trying to do is to set up a delete confirm for a row in my datagrid. The confirm pops up ok, but the delete functionality never takes place. After I respond to delete the row, the page_load event fires again (which I expect), but no other event fires after that......
Here is a snippet from my html:
<asp:TemplateColumn HeaderText="Inactivate Member">
<ItemTemplate>
<asp:Button id="cmdDelete" runat="server" Text="Inactivate" CommandName="Delete" CausesValidation="false"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
The following is the delete confirm function in my html:
<script>
function getdelconfirm()
{
if (confirm("Are you sure you want to inactivate this member?")==true)
return true;
else
return false;
}
</script>
The following is the code in my page_load event:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
If Not IsPostBack Then
If Not Request.QueryString.Item("strMsg") Is Nothing Then 'Capture success msg from child screen
Response.Write("<script>alert('" & Request.QueryString.Item("strMsg") & "');</script>")
End If
'Initialize Viewstate variables
lblWelcome.Text = "Welcome " & HttpContext.Current.User.Identity.Name & ". Today is " & FormatDateTime(Now, DateFormat.GeneralDate)
LoadMembers()
End If
DsNCVAC1 = Cache.Get("Category")
dvMembers = DsNCVAC1.Membership.DefaultView
DataGrid1.DataSource = dvMembers
DataGrid1.DataBind()
Catch exException As InvalidCastException 'Used for session timeout
Server.Transfer("..\..\Default.aspx")
Catch exException As ThreadAbortException
'Technically, Server.Transfer or Response.Redirect throws an exception. Catch it here and ignore it.
End Try
End Sub
The following is the code in my itemdatabound event:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
Dim strQueryString As String
If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim hylUserID As HyperLink = CType(e.Item.FindControl("hylUserID"), HyperLink)
Dim txtFirstName As Label = CType(e.Item.FindControl("txtFirstName"), Label)
Dim txtLastName As Label = CType(e.Item.FindControl("txtLastName"), Label)
strQueryString = String.Empty
strQueryString = "?MemberID=" & DataGrid1.DataKeys(e.Item.ItemIndex) & "&FirstName=" & txtFirstName.Text & "&LastName=" & txtLastName.Text & "&AddMember=" & False
hylUserID.NavigateUrl = "MemberAdminEdit.aspx" & strQueryString
End If
End Sub
The following is the code from my itemcreated event:
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated
If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim btnButton As Button
btnButton = CType(e.Item.Cells(6).FindControl("cmdDelete"), Button)
btnButton.Attributes.Add("onclick", "return getdelconfirm();")
End If
End Sub
The following is the start of some code from my datagrid1_deletecommand event:
Public Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
.
.
.
The following is the start of the code from my itemcommand event:
Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand
If e.CommandName = "Delete" Then
.
.
.
I have both the itemcommand and deletecommand events in here, because I was trying out several different methods. The problem is, like I said before, that none of the above events fire after the page_load event is fired when I press ok on the popup confirmation.
What do I need to do in order to have the appropriate event fire after the page_load event fires when I respond ok to the confirm in order to perform the delete functionality?
All I'm trying to do is to set up a delete confirm for a row in my datagrid. The confirm pops up ok, but the delete functionality never takes place. After I respond to delete the row, the page_load event fires again (which I expect), but no other event fires after that......
Here is a snippet from my html:
<asp:TemplateColumn HeaderText="Inactivate Member">
<ItemTemplate>
<asp:Button id="cmdDelete" runat="server" Text="Inactivate" CommandName="Delete" CausesValidation="false"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
The following is the delete confirm function in my html:
<script>
function getdelconfirm()
{
if (confirm("Are you sure you want to inactivate this member?")==true)
return true;
else
return false;
}
</script>
The following is the code in my page_load event:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
If Not IsPostBack Then
If Not Request.QueryString.Item("strMsg") Is Nothing Then 'Capture success msg from child screen
Response.Write("<script>alert('" & Request.QueryString.Item("strMsg") & "');</script>")
End If
'Initialize Viewstate variables
lblWelcome.Text = "Welcome " & HttpContext.Current.User.Identity.Name & ". Today is " & FormatDateTime(Now, DateFormat.GeneralDate)
LoadMembers()
End If
DsNCVAC1 = Cache.Get("Category")
dvMembers = DsNCVAC1.Membership.DefaultView
DataGrid1.DataSource = dvMembers
DataGrid1.DataBind()
Catch exException As InvalidCastException 'Used for session timeout
Server.Transfer("..\..\Default.aspx")
Catch exException As ThreadAbortException
'Technically, Server.Transfer or Response.Redirect throws an exception. Catch it here and ignore it.
End Try
End Sub
The following is the code in my itemdatabound event:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
Dim strQueryString As String
If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim hylUserID As HyperLink = CType(e.Item.FindControl("hylUserID"), HyperLink)
Dim txtFirstName As Label = CType(e.Item.FindControl("txtFirstName"), Label)
Dim txtLastName As Label = CType(e.Item.FindControl("txtLastName"), Label)
strQueryString = String.Empty
strQueryString = "?MemberID=" & DataGrid1.DataKeys(e.Item.ItemIndex) & "&FirstName=" & txtFirstName.Text & "&LastName=" & txtLastName.Text & "&AddMember=" & False
hylUserID.NavigateUrl = "MemberAdminEdit.aspx" & strQueryString
End If
End Sub
The following is the code from my itemcreated event:
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated
If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim btnButton As Button
btnButton = CType(e.Item.Cells(6).FindControl("cmdDelete"), Button)
btnButton.Attributes.Add("onclick", "return getdelconfirm();")
End If
End Sub
The following is the start of some code from my datagrid1_deletecommand event:
Public Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
.
.
.
The following is the start of the code from my itemcommand event:
Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand
If e.CommandName = "Delete" Then
.
.
.
I have both the itemcommand and deletecommand events in here, because I was trying out several different methods. The problem is, like I said before, that none of the above events fire after the page_load event is fired when I press ok on the popup confirmation.
What do I need to do in order to have the appropriate event fire after the page_load event fires when I respond ok to the confirm in order to perform the delete functionality?