This is a migrated thread and some comments may be shown as answers.

RadTextBox get_value error in User Control

2 Answers 112 Views
Input
This is a migrated thread and some comments may be shown as answers.
Yoongu
Top achievements
Rank 1
Yoongu asked on 07 Oct 2014, 10:24 AM
Hi,

It does not recognize the get_value method in my custom button object.

.aspx calling the user control
...
<
telerik:RadTextBox ID="textBoxSearchItemCode" ClientInstanceName="textBoxSearchItemCode" runat="server" Width="90px" CssClass="inline">
</telerik:RadTextBox>
<telerik:RadTextBox ID="textBoxSearchItemName" ClientInstanceName="textBoxSearchItemName" runat="server" Width="190px" CssClass="inline">
</telerik:RadTextBox>
<cc1:JPopup ID="popupItem" runat="server" PopupType="Item" CodeControl="textBoxSearchItemCode" NameControl="textBoxSearchItemName
"
OKScript="Search();"/>
...

user control JPopup.cs
namespace My.Web.JControl.JPopup
{
    [DefaultProperty("Text")]
    [DefaultEvent("OK")]
    [ToolboxData("<{0}:Popup runat=server></{0}:Popup>")]
    public class JPopup : WebControl, IPostBackEventHandler
    {
 
        public JPopup()
            : base()
        {
            UseOKServerEvent = false;
            OKScript = "";
            CodeControl = "";
            NameControl = "";
            PopupControl = "";
            PopupType = ePopupType.None;
            Hidden = false;
        }
 
        #region Properties
 
        /// <summary>
        /// Use OKEvent
        /// </summary>
        [Bindable(true),
        Category("Event")]
        public bool UseOKServerEvent
        {
            get
            {
                return (bool)ViewState["PopupUseOKServerEvent"];
            }
            set
            {
                ViewState["PopupUseOKServerEvent"] = value;
            }
        }
 
        /// <summary>
        /// OKEvent Handler for Javascript
        /// </summary>
        [Bindable(true)]
        [Category("Event")]
        [Editor(typeof(OKEventEditor), typeof(UITypeEditor))]
        public string OKScript
        {
            get
            {
                return (string)ViewState["PopupOKScript"];
            }
            set
            {
                ViewState["PopupOKScript"] = value;
            }
        }
 
        #endregion
 
        #region Binding Property
 
        // column to editbox mapping
        [Bindable(true),
        DefaultValue(""),
        Category("Binding")]
        public string CodeControl
        {
            get
            {
                return (string)ViewState["PopupCodeControl"];
            }
            set
            {
                ViewState["PopupCodeControl"] = value;
            }
        }
 
        [Bindable(true),
        DefaultValue(""),
        Category("Binding")]
        public string NameControl
        {
            get
            {
                return (string)ViewState["PopupNameControl"];
            }
            set
            {
                ViewState["PopupNameControl"] = value;
            }
        }
 
        // column to editbox mapping
        [Bindable(true),
        DefaultValue(""),
        Category("Binding")]
        public string PopupControl
        {
            get
            {
                return (string)ViewState["PopupPopupControl"];
            }
            set
            {
                ViewState["PopupPopupControl"] = value;
            }
        }
 
        [Bindable(true),
        DefaultValue(""),
        Category("Binding")]
        public string Parameter
        {
            get
            {
                return (string)ViewState["PopupParameter"];
            }
            set
            {
                ViewState["PopupParameter"] = value;
            }
        }
 
        #endregion
 
        #region PopupType Property
 
        [Bindable(true)]
        [Category("PopupType")]
        [DefaultValue(ePopupType.None)]
        public ePopupType PopupType
        {
            get
            {
                return (ePopupType)ViewState["PopupType"];
            }
            set
            {
                ViewState["PopupType"] = value;
            }
        }
 
        [Bindable(true)]
        [Category("PopupType")]
        [DefaultValue(false)]
        public bool Hidden
        {
            get
            {
                return (bool)ViewState["PopupHidden"];
            }
            set
            {
                ViewState["PopupHidden"] = value;
            }
        }
 
        public enum ePopupType { None, User, Customer, PoCustomer, Item, MoldItem, PowerChart };
         
        #endregion
 
 
        #region Render
 
        /// <summary>
        /// Render this control to the output parameter specified.
        /// </summary>
        /// <param name="output"> The HTML writer to write out to </param>
        ///
        protected override void RenderContents(HtmlTextWriter output)
        {
            StringBuilder sbRender = new StringBuilder();
            // Design Mode
            if (this.DesignMode)
            {
                sbRender.Append("<div style=\"VERTICAL-ALIGN: bottom; DISPLAY:inline;POSITION:relative; \" onMouseOver = \"this.style.cursor = 'hand'\">");
                sbRender.Append("<img id = \"" + ID + "\" name = \"" + ID + "\"");
                sbRender.Append(string.Format(" src=\"/{0}/Images/Main/popup.gif\"/>", ConfigurationManager.AppSettings["WebSiteName"]));
 
                sbRender.Append("</div>");
                output.Write(sbRender);
                return;
            }
 
            sbRender.Append("<script type='text/javascript'>");
            sbRender.Append(string.Format(@"
function Popup_{0}()
{{
    var popSearchCode = $find('<%= {1}.ClientID %>').get_value(); <<---- here!!!!
    var popSearchName = $find('<%= {2}.ClientID %>').get_value();", ID, CodeControl, NameControl));
.......

error :
SCRIPT5007: Unable to get value of the property 'get_value()': object is null or undefined.

How Can I use RadTextBox get_value method?

Thank you.

2 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 10 Oct 2014, 06:55 AM
Hello Yoongu,

Thank you for contacting Telerik Support.

First, I have to mention that this is not related to our controls in any way and in general is out of the scope of our Support Service.

However, the issue that you are experiencing is due to the fact that it is not possible to have server code blocks declared in such manner. Server code block could be used only within the markup of the page (or the UserControl).

If you inspect the generated JavaScript you will notice that you are actually trying to use $find with the following string "<%= textBoxSearchItemCode.ClientID %>"  which will not find anything. The correct way for achieving this must be by providing the ClientID of the associated controls directly, but you will have to get reference to those controls on server-side:
            string CodeControlClientID = ......;
            string NameControlClientID = ......;
 
            sbRender.Append(string.Format(@"
function Popup_{0}()
{{
    var popSearchCode = $find('{1}').get_value(); <<---- here!!!!
    var popSearchName = $find('{2}').get_value();", ID, CodeControlClientID, NameControlClientID));

If you have any questions related to our controls, please feel free to contact us again.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Yoongu
Top achievements
Rank 1
answered on 13 Oct 2014, 01:50 AM
$find('{1}').get_Value()
It works well.

Thank you!
Tags
Input
Asked by
Yoongu
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Yoongu
Top achievements
Rank 1
Share this question
or