Current filter:
          You should refresh the page.
          Not Logged In

          Howto create a custom control

          0
            • Hi!

              At the moment, I'm trying to create a custom 'asp.net server control' (a .CS!! not an ASCX!!), which should contain some DevExpress asp.net controls. As a simple example, I'm just trying to render a ASPxTextbox within my custom control.

              When being rendered, I get the following javascript error :

              "Microsoft JScript runtime error: 'ASPxClientTextBox' is undefined"

              So, I guessed some initialitation scripts are missing. Then I tried to including this base script by calling :

              ASPxTextBox.RegisterBaseScript(this.Page);

              This however did not work; the same javascript error still occurs.

              The full code if my simple example custom control can be found below:
              -------------------------------------------------------------

              using System;
              using System.Collections.Generic;
              using System.ComponentModel;
              using System.Linq;
              using System.Text;
              using System.Web;
              using System.Web.UI;
              using System.Web.UI.WebControls;
              using DevExpress.Web.ASPxCallback;
              using DevExpress.Web.ASPxPopupControl;
              using DevExpress.Web.ASPxGridView;
              using System.Drawing;
              using System.Web.UI.HtmlControls;
              using DevExpress.Web.ASPxEditors;
              using DevExpress.Web.ASPxClasses;

              namespace TypeSelector
              {
                  [DefaultProperty("OutputType")]
                  [ToolboxData("<{0}:TypeSelector runat=server></{0}:TypeSelector>")]
                  public class TypeSelector : WebControl
                  {

                      private ASPxTextBox textboxResult = new ASPxTextBox();

                 
                      #region Public properties

                      public string OutputType
                      {
                          get
                          {
                              String s = (String)ViewState["OutputType"];
                              return s;
                          }

                          set
                          {
                              ViewState["OutputType"] = value;
                          }
                      }

                      #endregion

                      protected override void OnLoad(EventArgs e)
                      {
                          base.OnLoad(e);
                          ASPxTextBox.RegisterBaseScript(this.Page);
                      }

                      protected override void OnInit(EventArgs e)
                      {
                          base.OnInit(e);

                          //textbox
                          textboxResult.ID = this.ID + "TextboxResult";
                          textboxResult.Font.Size = FontUnit.XXSmall;
                          textboxResult.ReadOnly = true;
                          textboxResult.Width = Unit.Pixel(170);

                      }

                      protected override void RenderContents(HtmlTextWriter output)
                      {
                          output.Write(OutputType);
                          textboxResult.RenderControl(output);
                          
                      }
                  }
              }

          0

          My question of course is:

          How should I create a custom control?
          And why do I get this javascript error?

          0

          Hi Jan;

          I'm sorry for the delay.
          We're currently working on your question and will answer you as soon as possible.

          Thanks
          Kate.

          0

          I just found this forum entry : http://community.devexpress.com/forums/p/60943/206181.aspx
          After reading it, I realized that I could be suffering the same.

          So I added this 'OnPreRender' overridden method to my class :

          protected override void OnPreRender(EventArgs e)
          {

                      base.OnPreRender(e);

                      Controls.Add(textboxResult);
          }

          Now it works fine; I dont get the javascript error.
          Thanks anyway!

          0

          Found the answer at : http://community.devexpress.com/forums/p/60943/206181.aspx

          You must  log in  or  register  to leave an answer