0

I have a repeater containing, amongst others, two buttons. One of the buttons is an ASP.NET button whilst the other is of the type "input type="button"".

Now, in my code-behind, I want to retrieve both buttons from the repeater to either hide them or show them. I have successfully hidden the ASP.NET button however I do not know how to retrieve the other button.

Here is some code in ASP.NET:

<input type="button" name="ButtonEditUpdate" runat="server" value="Edit Update" class="ButtonEditUpdate" />
<asp:Button ID="ButtonDeleteUpdate" CssClass="ButtonDeleteUpdate" CommandName="Delete" runat="server" Text="Delete Update" />

Here is the code-behind:

protected void RepeaterUpdates_ItemBinding(object source, RepeaterItemEventArgs e)
{
    RepeaterItem item = e.Item;
    TextBox Update_ID = (TextBox)item.FindControl("TextBoxUpdateID_Repeater");
    //Button Edit_Update = (Button)item.FindControl("ButtonEditUpdate");
    Button Delete_Update = (Button)item.FindControl("ButtonDeleteUpdate");

    if (Social_ID == String.Empty)
    {
        //Edit_Update.Visible = false;
        Delete_Update.Visible = false;
    }
}

How can I retrieve the HTML button and hide it since it is NOT an ASP.NET button?

0

3 Answers 3

2

That button is a HTML control and will be of type System.Web.UI.HtmlControls.HtmlButton

 System.Web.UI.HtmlControls.HtmlButton button = item.FindControl("ButtonEditUpdate") as System.Web.UI.HtmlControls.HtmlButton;
 if(button!=null)
      button.Visible = false;
Sign up to request clarification or add additional context in comments.

Comments

0

In general you cannot straightly retrieve a plain-old HTML button because ASP.NET considers that as part of the text markup. Fortunately, you already added runat="server" that makes your button a server control.

The easiest way is to use an HtmlButton control. But in your markup you need the id attribute

<input type="button" name="ButtonEditUpdate" runat="server" value="Edit Update" class="ButtonEditUpdate" id="ButtonEditUpdate" />

Then in the code behind

//Button Edit_Update = (Button)item.FindControl("ButtonEditUpdate");
HtmlButton Delete_Update = (HtmlButton)item.FindControl("ButtonEditUpdate");

Comments

0

If you just want to set the visibility you shouldn't need to cast it.

 var myButton = e.Item.FindControl("ButtonEditUpdate");
 if(myButton != null)
    myButton.Visible = false;

EDIT: you should give your button an ID.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.