Results 1 to 6 of 6

Thread: confirmation box

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    confirmation box

    I am having some difficulty getting my message box to display. If I use a regular asp button, I place the javascript in the page_load event and it works fine. The problem is this button I'm using now is a datagrid button. Is there another procedure I can declare this code in?

    Code:
    Public Sub DeleteBid(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
            'check which row has been selected
            Dim selectedRow As String = DataGrid1.DataKeys(e.Item.ItemIndex)
            Dim btnDelete As Button
            btnDelete = e.Item.Cells(4).Controls(0) '<---5th column, first control 
            btnDelete.Attributes("onclick") = "javascript:return confirm('Are you sure you want to delete \n    Bid Record " & selectedRow & "?')"

  2. #2
    Addicted Member Dmyze's Avatar
    Join Date
    Mar 2002
    Location
    Seattle
    Posts
    160
    Use the DataGrid's ItemCreated Routine:

    Code:
      Private Sub dg_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg.ItemCreated
    
        Select Case e.Item.ItemType
          Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem
    
            Dim cmdDelete As Button = e.Item.FindControl("cmdDelete")
    
            If Not cmdDelete Is Nothing Then
              Dim x As Common.DbDataRecord = e.Item.DataItem
              Dim sName As String
    
              If Not x Is Nothing Then
                sName = x.GetValue(1)
              End If
    
              cmdDelete.Attributes.Add("onclick", "return confirm('Are you sure you want to delete " & sName & "?');")
            End If
        End Select
    -Daryl
    "Two More Rolls of Duct tape, and the world is mine!"
    VB.NET Guru

  3. #3

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    still no message box displays...

  4. #4
    Addicted Member Dmyze's Avatar
    Join Date
    Mar 2002
    Location
    Seattle
    Posts
    160
    Are you using a Template Column? You'll need to do that.

    Code:
                    <asp:TemplateColumn>
                      <ItemTemplate>
                        <asp:Button id="cmdDelete" runat="server" Text="Delete"></asp:Button>
                      </ItemTemplate>
                    </asp:TemplateColumn>
    -Daryl
    "Two More Rolls of Duct tape, and the world is mine!"
    VB.NET Guru

  5. #5

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    it's not a button though...it's a buttonColumn

    Code:
    <asp:ButtonColumn Text="Delete" ButtonType="PushButton" HeaderText="DELETE" CommandName="Delete"></asp:ButtonColumn>

  6. #6
    Addicted Member Dmyze's Avatar
    Join Date
    Mar 2002
    Location
    Seattle
    Posts
    160
    If you use a button column you leave the button in control of the datagrid, if you want to add attributes you have to make your own button column by using a Template Column as shown above. (Anyone can correct me if I'm wrong, but this is the only way I've found it to work.)
    -Daryl
    "Two More Rolls of Duct tape, and the world is mine!"
    VB.NET Guru

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width