Button in WebCustomControl don't fire the onclick event, why?

Discussion in 'ASP .Net Building Controls' started by Stefan, Jul 8, 2003.

  1. Stefan

    Stefan Guest

    Maybe someone sees my mistake? The Button-OnClick-Event never fires...


    --------------------------------------------------------
    The code from the WebCostumControl:
    --------------------------------------------------------
    using System;
    using System.Data;
    using System.Data.OleDb;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using artiso_lib;
    namespace artiso_lib
    {
    [DefaultProperty("IndexserverCatalog"), ToolboxData("<{0}:IndexserverSearch
    runat=server></{0}:IndexserverSearch>")]
    public class IndexserverSearch : System.Web.UI.WebControls.WebControl
    {
    [Bindable(true), Category("Appearance"), DefaultValue(""),
    EditorBrowsable(EditorBrowsableState.Always), Description("Name des
    Indexserver-Katalogs.")]
    public string IndexserverCatalog
    {
    get {return ViewState["IndexserverCatalog"].ToString();}
    set {ViewState["IndexserverCatalog"] = value;}
    }
    [Bindable(true), Category("Appearance"), DefaultValue(""),
    Description("Maximale Anzahl der Suchergebnisse. Keine Angabe für alle
    Suchergebnisse.")]
    public int MaxSearchResults
    {
    get {return (int)ViewState["MaxSearchResults"];}
    set {ViewState["MaxSearchResults"] = value;}
    }
    [Bindable(true), Category("Appearance"), DefaultValue("Styles.css"),
    Description("StyleSheet Datei für die Formatierung des DataGrids.")]
    public string StyleSheetFile
    {
    get {return ViewState["StyleSheetFile"].ToString();}
    set {ViewState["StyleSheetFile"] = value;}
    }
    [Bindable(true), Category("Appearance"), DefaultValue("fdgsd"),
    Description("Spalten die vom Indexserver gelesen werden sollen.")]
    public string Columns
    {
    get {return ViewState["GetColumns"].ToString();}
    set {ViewState["GetColumns"] = value;}
    }
    [Bindable(true), Category("Appearance"), DefaultValue("Suche"),
    Description("Beschriftung des \"Suche\" Buttons.")]
    public string SearchButtonText
    {
    get {return ViewState["SearchButtonText"].ToString();}
    set {ViewState["SearchButtonText"] = value;}
    }
    public DataTable Search(string SearchString)
    {
    Cisso.CissoQueryClass cqc = new Cisso.CissoQueryClass();
    cqc.Catalog = IndexserverCatalog;
    cqc.MaxRecords = MaxSearchResults;
    cqc.CiFlags = "SHALLOW";
    cqc.Query = SearchString;
    cqc.Columns = Columns;
    cqc.SortBy = "Rank[d]";
    ADODB.Recordset rsIX =
    (ADODB.Recordset)cqc.CreateRecordset("nonsequential");
    OleDbDataAdapter daConvertToDataset = new OleDbDataAdapter();
    DataSet ds = new DataSet();
    daConvertToDataset.Fill(ds, rsIX, "indexServerDirectories");
    if (ds.Tables["indexServerDirectories"].Rows.Count == 0)
    {
    Page.RegisterClientScriptBlock("NoSearchResult", "<script
    language='javascript'>alert('Die Suche konnte keine entsprechenden Dokumente
    finden.');</script>");
    }
    return ds.Tables["indexServerDirectories"];
    }
    private void btnSearch_Click(object sender, System.EventArgs e)
    {
    DataTable dt = this.Search(((TextBox)this.FindControl(this.ID +
    "SearchString")).Text);
    Page.RegisterClientScriptBlock("x", "<script
    language='javascript'>alert("+dt.Rows.Count+");</script>");
    }
    protected System.Web.UI.WebControls.Button btn = new Button();
    protected System.Web.UI.WebControls.TextBox tb = new TextBox();
    protected override void OnInit(System.EventArgs e)
    {
    btn.Click += new System.EventHandler(this.btnSearch_Click);
    }
    override protected void CreateChildControls()
    {
    if (IndexserverCatalog.Trim() == "")
    {
    Page.RegisterClientScriptBlock("CatalogError", "<script
    language='javascript'>alert('Sie haben keinen Indexserver-Katalog angegeben,
    bitte ändern Sie Ihre Seite entsprechend.');</script>");
    return;
    }
    if (Columns.Trim() == "")
    {
    Page.RegisterClientScriptBlock("ColumnError", "<script
    language='javascript'>alert('Sie haben keine zu suchenden Spalten angegeben,
    bitte ändern Sie Ihre Seite entsprechend.');</script>");
    return;
    }
    tb.ID = this.ID + "SearchString";
    tb.Attributes.Add("runat", "server");
    this.Controls.Add(tb);
    btn.ID = this.ID + "btnSearch";
    btn.Attributes.Add("runat", "server");
    btn.Text = SearchButtonText;
    this.Controls.Add(btn);
    }
    }
    }
    ------------------------------------------------------------
    End of code from the WebCostumControl:
    --------------------------------------------------------------

    ------------------------------------------------------------
    Code from CodeBehind of Webpage:
    --------------------------------------------------------------
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    namespace Indexserver
    {
    public class WebForm1 : System.Web.UI.Page
    {
    protected artiso_lib.IndexserverSearch IndexserverSearch1;
    private void Page_Load(object sender, System.EventArgs e)
    {
    if (!IsPostBack)
    {
    IndexserverSearch1.Columns = "Directory";
    IndexserverSearch1.IndexserverCatalog = "Test";
    IndexserverSearch1.MaxSearchResults = 200;
    IndexserverSearch1.SearchButtonText = "Suchen...";
    }
    }
    override protected void OnInit(EventArgs e)
    {
    InitializeComponent();
    base.OnInit(e);
    }
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);
    }
    }
    }
     
    Stefan, Jul 8, 2003
    #1
    1. Advertisements

  2. Stefan

    Stefan Guest

    Thanks Teemu Keiski!

    It was really the INamingContainer interface..

    For those of you, don't understand what was wrong:

    old: public class IndexserverSearch : System.Web.UI.WebControls.WebControl
    new: public class IndexserverSearch : System.Web.UI.WebControls.WebControl,
    INamingContainer

    Regards, Stefan



     
    Stefan, Jul 9, 2003
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.