Telerik
Home / Community / Forums / RadControls for ASP.NET: Input / Custom Control problems

Custom Control problems

Feed from this thread
  • jas avatar

    Posted on Jul 15, 2006 (permalink)

    I want to create a web custom control which is inherited from the Rad input box (masked input). The idea is that in read-only mode, the control will render as a label, otherwise it will render as a proper input box. I have done this with the normal MS text box and all works fine.

    But, I can not get this to work with this Rad input box (I want to do the same trick with a lot of other input controls as well), and keep getting the error "cc1.MyRadInput is not a known element"

    My class is declared like this:

    [ParseChildren(false)]
    public class MyRadInput : Telerik.WebControls.RadMaskedTextBox

    and the render method is:

        protected override void RenderContents(HtmlTextWriter output)
        {
          //base.RenderControl(output);
          //base.RenderContents(output);
          base.Render(output);
        }

    I have tried the other 2 render methods with no effect. The control shows up in the toolbox, and it is from there that I am dragging it to the page. Another control based on the MS TextBox is in the same library and continues to work fine. The ParseChildren attribute was a shot in the dark ref another forum, but has no effect.

    So, a) can I derive my own control from a Rad one and b) how, so as to avoid this error!!??

    As I have spent a whole afternoon trying to figure this out, any help would be much appreciated.

    James.

    Reply

  • Posted on Jul 15, 2006 (permalink)

    Hi James,

    I haven't tried to make a custom control inherited from rad.input before but I have with rad.callback v1 and have enjoyed a lot of success.

    I haven't used them since rad.callback v2 was released (these days I use a rad.ajaxpanel and my custom controls are inherited from asp.net controls) but I can attest that at the time they worked flawlessly.

    What version of .Net are you using? I'm still using .Net 1.1. I'm not sure how much direct advice I can provide.

    From your description I would guess that your problem is with the "<@ Register" tag that is getting generated when you place one of your controls on the page. Verify that the tag syntax is correct.

    Reply

  • jas avatar

    Posted on Jul 15, 2006 (permalink)

    Josef:

    Thanks for your encouraging reply - I did get it working just recently - the key was to add the line:

    <%@ Register Assembly="RadInput.Net2" Namespace="Telerik.WebControls" TagPrefix="radI" %>

    in addition to a similar line registering my custom controls.

    However, I am still left with a javascript error:

    "RadMaskedTextBox is not defined"

    in reference to this script in the page source:

          <span id="MyRadInput1_wrapper"><script type="text/javascript" src="/WebTest/RadControls/Input/Scripts/1_2_0/RadInput.js"></script><input type="hidden" id="MyRadInput1" value="" /><input type="hidden" name="MyRadInput1" value="" id="MyRadInput1_Value" /><input id="MyRadInput1_TextBox" name="MyRadInput1_TextBox" type="text" value="" /><script type="text/javascript">window["MyRadInput1"] = new RadMaskedTextBox("MyRadInput1", "");window["MyRadInput1"].PromptChar="_";window["MyRadInput1"].DisplayPromptChar="_";window["MyRadInput1"].SetMask();window["MyRadInput1"].SetValue(window["MyRadInput1"].field.value);window["MyRadInput1"].Initialize();</script></span>
    <span id="RadMaskedTextBox1_wrapper"><input type="hidden" id="RadMaskedTextBox1" value="" /><input type="hidden" name="RadMaskedTextBox1" value="" id="RadMaskedTextBox1_Value" /><input id="RadMaskedTextBox1_TextBox" name="RadMaskedTextBox1_TextBox" type="text" value="" /><script type="text/javascript">window["RadMaskedTextBox1"] = new RadMaskedTextBox("RadMaskedTextBox1", "");window["RadMaskedTextBox1"].PromptChar="_";window["RadMaskedTextBox1"].DisplayPromptChar="_";window["RadMaskedTextBox1"].SetMask();window["RadMaskedTextBox1"].SetValue(window["RadMaskedTextBox1"].field.value);window["RadMaskedTextBox1"].Initialize();</script></span></div>

    (excuse long line)
    This arises from ( I assume) my aspx line:

    <cc1:MyRadInput ID="MyRadInput1" runat="server" Text="Hello!"></cc1:MyRadInput>

    and a script element:

    <script type='text/javascript' language='javascript' src='/RadControls/Input/Scripts/1_2_0/RadInput.js'></script>

    This must be some installation problem, yet I
     have copied ALL of the RadControls folder to the WebTest (root) folder...

    Obviously the javascript does not recognise RadMaskedTextBox - what to do?

    Any light to shed on this problem much appreciated.

    BTW, I am using VS 2005 and Q1 2006 Telerik

    Regards

    James.

    Reply

  • Telerik Admin admin's avatar

    Posted on Jul 18, 2006 (permalink)

    Hi James,

    "RadMaskedTextbox is not undefined" means that for some reason the javascript file did not make it to the client. Can you try to include it manually at the top of the page? Also, check which version of the input you have (the latest is 1.3.1). Maybe this is the reason for the problem?

    All the best,
    Petyo
    the telerik team

    Reply

  • Chris Burge avatar

    Posted on Nov 6, 2006 (permalink)

    Did you finally get it working.  My control shows but I can't input data.

    Reply

  • Telerik Admin admin's avatar

    Posted on Nov 7, 2006 (permalink)

    Hi Chris,

    We've already unswered your question in the support ticket you've opened on the subject. In order to achieve your goal you will have to set a Mask before setting any text to the control.

    Best wishes,
    Paul
    the telerik team

    Reply

  • Chris Burge avatar

    Posted on Nov 7, 2006 (permalink)

    Ahhhh....thanks and sorry, I never saw your reply.  :P  Anywho, it would be nice to have the mask optional so I don't have to do extra programming.  My 2 cents.

    Thanks,
    Chris

    Reply

  • Telerik Admin admin's avatar

    Posted on Nov 7, 2006 (permalink)

    Hi Chris,

    Unfortunately, you cannot achieve your goal with the current version of r.a.d.input. RadMaskedTextBox is a generic masked box control and is not always suitable for free text input. We fully understand your concerns, but unfortunately, it is not expected for such a control to mimic the standard textbox behavior.

    We are currently thinking of extending our data input controls and providing a set of task-oriented data input controls in addition to the RadMaskedTextBox control (in particular, we are currently thinking of r.a.d.textbox with a skinning possibility). Meanwhile, we hope that RadMaskedTextBox will be applicable in your scenario.

    Thanks for your understanding.

    Sincerely yours,
    Paul
    the telerik team

    Reply

  • Posted on Nov 14, 2006 (permalink)

    Hi Paul,
    I just thought I throw my request in about an 'unmasked' text box.

    Any chance you can move from 'thinking about it', to doing actually doing it - pretty please. :-)
    I've had to seriously downgrade the look of my application, because I can't use the skinning affects on a textbox that you've achieved with the Masked Text Box. 

    I will have to find time to write my own textbox control now :-(

    Keep up the good work.
    Chris McGuigan


    Reply

  • Telerik Admin admin's avatar

    Posted on Nov 14, 2006 (permalink)

    Hello Chris,

    You can beatify the regular textbox with the desired r.a.d.input skin. Most of the javascript we use is not related to the control appearance - we have hooked up to some of the input events (onfocus, onblur, onmouseover, onmouseout), and we are changing the textbox css class (on the client-side - className) property there, using JavaScript. You can achieve the same result easily, and yes, it will be cross browser compatible. Here's a sample code snippet that demonstrates the approach.

    <form id="form1" runat="server">  
            <radI:RadMaskedTextBox ID="RadMaskedTextBox2" runat="server" 
                DisplayMask="##.##.##" DisplayPromptChar=" " Mask="##.##.##" 
                PromptChar="_" Skin="Gold">  
            </radI:RadMaskedTextBox> 
            This is a telerik RadMaskedTextBox<br /> 
            <br /> 
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>This  
            is a regular TextBox  
     
            <script type="text/javascript">  
           function Beautify ()  
           {  
            var textBoxes = GetTextBoxes();   
            for (var i = 0; i < textBoxes.length; i ++)  
            {  
             var textBox = textBoxes[i];  
             textBox.className = "Default_Gold";  
             textBox.onfocus = function ()  
             {  
              this.className = "Focus_Gold";  
             }  
               
             textBox.onblur = function ()  
             {  
              this.className = "Default_Gold";  
             }       
            }  
           }  
             
           function GetTextBoxes ()  
           {  
            return [  
             document.getElementById('<%=TextBox1.ClientID%>')  
            ]  
           }  
             
           Beautify();  
            </script> 
     
        </form> 


    All the best,
    Paul
    the telerik team

    Reply

Powered by Sitefinity ASP.NET CMS

Contact Us | Site Feedback | Terms of Use | Privacy Policy
Copyright © 2002-2009 Telerik. All rights reserved.