wsyeager Posted January 2, 2006 Posted January 2, 2006 (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 January 2, 2006 by PlausiblyDamp Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
mark007 Posted January 2, 2006 Posted January 2, 2006 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. Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code Net
wsyeager Posted January 3, 2006 Author Posted January 3, 2006 I added a recursive "FindControl" method since the butoon is inside of a placeholder control. This did the trick just fine. Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.