Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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:

 


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

 

The following info is in my code-behind:

 


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?

Edited by PlausiblyDamp

Thanks,

 

Bill Yeager (MCP, BCIP)

Microsoft Certified Professional

Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer

YeagerTech Consulting, Inc.

Posted

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.

Please check the Knowledge Base before you post.

"Computers are useless. They can only give you answers." - Pablo Picasso

The Code Net

Posted

I added a recursive "FindControl" method since the butoon is inside of a placeholder control.

 

This did the trick just fine.

Thanks,

 

Bill Yeager (MCP, BCIP)

Microsoft Certified Professional

Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer

YeagerTech Consulting, Inc.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...