0

I'd like to add OnClick action to my button (buttonSearch) in WebCustomControl. Please help me because Event isn't running. I tried a search in google but I did not find anything :(

PS. Sorry for my English :)

Thank you very much :)

namespace TestApp1.ctrls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
    public class WebCustomControl1 : WebControl
    {

        private string searchText
        {
            get
            {
                if (ViewState["searchText"] == null)
                {
                    return "";
                }
                else
                {
                    return (String)ViewState["searchText"];
                }
            }
            set
            {
                ViewState["searchText"] = value;
            }
        }

        Panel searchPanel = new Panel() { Visible = true, Height = 62, Width = 321 };
        Label LabelSearch = new Label() { Text = "Wyszukaj: " };
        TextBox textBoxSearch = new TextBox() { Height = 16, Width = 184 };
        Button buttonSearch = new Button() { Text = "Wyszukaj", Width = 259 };
        //END PANEL SEARCH
        protected override void RenderContents(HtmlTextWriter output)
        {
            //Button search click event
            buttonSearch.Click += ButtonSearch_Click;
            searchPanel.Controls.Add(LabelSearch);
            searchPanel.Controls.Add(textBoxSearch);
            searchPanel.Controls.Add(new LiteralControl("<br />"));
            searchPanel.Controls.Add(buttonSearch);
            searchPanel.RenderControl(output);
        }

        private void ButtonSearch_Click(object sender, EventArgs e)
        {
            searchPanel.Visible = false;
        }
    }
}
Harsha pps
  • 2,012
  • 2
  • 25
  • 35
kobi55
  • 93
  • 2
  • 10

2 Answers2

0

Does not look like you have added a EventHandler. Something like:

buttonSearch.Click += new EventHandler(this.ButtonSearch_Click);
Daniel R
  • 70
  • 7
0

I have a solution :) INamingContainer :)

public class WebCustomControl1 : WebControl, INamingContainer
kobi55
  • 93
  • 2
  • 10