[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

e.CommandName not being evaluated when ImageButton is clicked in my DataGrid

Posted on 2007-10-03
9
Medium Priority
?
1,319 Views
Last Modified: 2010-08-05
I'm trying to figure out why this existing delete code isn't being called.

1        Private Sub dgPhones_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgPhones.ItemCommand
2            Dim allowDelete As Integer = 100
3    
4            Select Case e.CommandName
5    
6                Case "Edit"
7                    dpPhoneType.ClearSelection()
8                    dpPrimary.ClearSelection()
9                    EditData(CInt(dgPhones.DataKeys(e.Item.ItemIndex)))
10                   pnlEditPhone.Visible = True
11                   btnAddPhone.Visible = False
12                   BindLeadPhones()
13                   pnlPhones.Height = New System.Web.UI.WebControls.Unit(180)
14               Case "Delete"
15                   allowDelete = DeletePhone(CInt(dgPhones.DataKeys(e.Item.ItemIndex)))
16                   If allowDelete = 100 Then
17                       BindLeadPhones()
18                   Else
19                       Response.Write("<script language=Javascript>")
20                       Response.Write("alert('You must make another phone number the Primary phone before you delete.')")
21                       Response.Write("</script>")
22                   End If
23           End Select
24  
25       End Sub
 
The problem is, previously this was working fine but the change I made was to use an actual ImageButton in an ItemTemplate rather than a stupid ButtonColumn or whatever that they had in this DatGrid Previously because first of it's easier to work with and second, I needed to fire off an OnClick event as well.

Anyway, here's my new ImageButton for the delete button defined in my DataGrid:
 
1    <asp:TemplateColumn HeaderText="Primary">
2          <ItemStyle Wrap="False" HorizontalAlign="Left" CssClass="datagridcell" />
3                <ItemTemplate>
4                      <nobr>
5                      <asp:ImageButton ID="btnDelete" ImageUrl="/Images/icons/redx.gif" CommandName="Delete" runat="server" />
6                      </nobr>
7                </ItemTemplate>
8          </asp:TemplateColumn
 
So when I step through and debug, it never gets back into the Select Case e.CommandName for my Delete button and not sure why.  I do have a JavaScript confirmation coming up asking "Are you sure you want to delete" when the user clicks the button and if I click OK in that JavaScript confirmation, the page refreshes but it's like it never returns to evaluate the e.CommandName in order to carry out the delete.  It just goes back to PageLoad again at the beginning after I click OK in my JavaScript Confirmation box instead of continueing onto the Select Case in my dgPhones_ItemCommand method....why is that?

Any help or ideas would be greatly appreciated.

0
Comment
Question by:dba123
8 Comments
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 20011683
did you try

Private Sub dgPhones_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgPhones.Command


instead of ItemCommand
0
 
LVL 1

Author Comment

by:dba123
ID: 20011693
They've always had ItemCommand.  And that Edit portion works fine and also did the Delete before when I didn't have an ImageBugtton and JavaScript and just had the ButtonCommand in the Grid.  So I don't think it's that.

I think it has everything to do with my JavaScript confirmation that comes up because when I confirm and click OK, the page does a postback and it's like it starts over and never continues on at the same place in code to continue evaluating the e.CommandName.  
0
 
LVL 1

Author Comment

by:dba123
ID: 20011825
In fact you must use ItemCommand, it makes no sense NOT to.  If you don't you get errors.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 23

Expert Comment

by:Saqib Khan
ID: 20012076
I believe within Datagrid/Repeater you can not use any Server Side Controls:( .
0
 
LVL 2

Expert Comment

by:sujithcnair
ID: 20012640
Hi adil we can use server controls inseide Datagrid

Dba please make sure that you are binding the datagrid when the page si not posted back

if not ispostback then

'function to bind datagrid

end if
0
 
LVL 1

Author Comment

by:dba123
ID: 20013120
thanks.  The DataGrid has been and is definitely being bound on check of IsPostBack
0
 
LVL 1

Accepted Solution

by:
dba123 earned 0 total points
ID: 20024034
I ended up using a LinkButton instead.  You can't do what I'm trying to do with an ImageButton for whatever reason.
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20042902
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question