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

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

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

    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("nonsequentia l");
    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);
    }
    }
    }

    ------------------------------------------------------------
    End of Code from CodeBehind of WebPage:
    --------------------------------------------------------------


    Stefan Guest

  2. Similar Questions and Discussions

    1. Onclick event
      I would like for certain Contribute users to be able to add on onclick event on links. How can they do this ? Thanks!
    2. onClick event on a Submit button
      I have a form that has one input field and a submit button that has an onclick event coded that calles a javascript function. If focus is on the...
    3. How to expose WebCustomControl event
      Hi, I have been working on this for more than a day, with no joy and I was wondering if someone could help me with this: I am trying to create...
    4. script ASP in an onClick event
      i need to insert, in a onClick event of a submit button in a form, a call to an ASP script, like follows: <INPUT TYPE="SUBMIT" NAME="btnSend"...
    5. fire button event programmatically
      From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a...
  3. #2

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

    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



    "Teemu Keiski" <joteke@aspalliance.com> schrieb im Newsbeitrag
    news:OKQyfjYRDHA.1624@tk2msftngp13.phx.gbl...
    > As a first look it is composite control. You need to implement
    > INamingContainer interface as well.
    >
    > And when you create controls on server-side you don't have to add
    > runat="server" for them. runat="server" on aspx declarative syntax
    specific
    > and you create control basically dynamically in this case. There's never
    > need for aspx syntax in such case.
    >
    > --
    > Teemu Keiski
    > MCP, Designer/Developer
    > Mansoft tietotekniikka Oy
    > [url]http://www.mansoft.fi[/url]
    >
    > ASP.NET Forums Moderator, [url]www.asp.net[/url]
    > AspAlliance Columnist, [url]www.aspalliance.com[/url]
    >
    > Email:
    > [email]joteke@aspalliance.com[/email]
    >
    > "Stefan" <swilhelm@artiso.com> wrote in message
    > news:e1iMlvVRDHA.2460@TK2MSFTNGP10.phx.gbl...
    > > 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("nonsequentia l");
    > > 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);
    > > }
    > > }
    > > }
    > >
    > > ------------------------------------------------------------
    > > End of Code from CodeBehind of WebPage:
    > > --------------------------------------------------------------
    > >
    > >
    >
    >

    Stefan Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139