Can't find the button....

wsyeager

Centurion
Joined
Apr 10, 2003
Messages
140
Location
Weston, FL
I'm trying to get an instance of a Delete button on my webform in order to display a warning msg to the user. I've done this type of thing several times for a button inside a datagrid for a user confirm to delete a particular record. this webform has no datagrid. Simply a delete button. However, the form is set up as having multiple placeholder controls depending upon which functionality is initially selected.

The following is the html within my webform:

Code:
<asp:Button id="btnDelete" Text="Delete" runat="server" class="eppbutton"/>

The following info is in my code-behind:

Visual Basic:
ElseIf Request.QueryString.Item("iManage") = 3 Then 'Delete
            plcAddFile.Visible = False
            plcAddFolder.Visible = False
            plcDelete.Visible = True
            plcEdit.Visible = False
            plcPublish.Visible = False
            plcCustomize.Visible = False
            plcContact.Visible = False
            'Set up a delete confirmation
            Dim btnDeleteFilefolder As Button
            btnDeleteFilefolder = DirectCast(Me.FindControl("btnDelete"), Button)
            btnDeleteFilefolder.Attributes.Add("onclick", "return getdelconfirm();")

While debugging, I get the following instance of the Delete button from within the Auto window:

- btnDelete {Text = "Delete"} System.Web.UI.WebControls.Button

As you can see, the ID of the button is availabile.

I'm getting an "Object not set to an instance of an object" on the boldfaced line of code above.

What am I doing wrong here where I can't get an instance of this object?
 
Last edited by a moderator:
You just need to declare the button:

Protected btnDelete as Button

within your code behind then refer to btnDelete. If you are using Visual Studio.Net then this will be doen automatically.
 
Back
Top