0

I am trying to make the input box show some text in the asp.net using c#, but after I run the code behind, nothing is displayed in the input box. The ui is RadNumericTextBox uiDistance. In class, I put this.uiDistance.Text = "123"; But in the webpage after run the code. I cannot see "123" is put in the uiDistance text box. How can I fix it?

Here is my aspx UsageControl2SubControl1.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UsageControl2SubControl1.ascx.cs" Inherits="WebControls.UsageControl2SubControl1" %>
<asp:HiddenField ID="uiRemoved" Value="false" runat="server" />
<asp:HiddenField ID="uiID" runat="server" />
<div class="form-group">    

    <div class="col-md-2 customColumnPadding">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <telerik:RadTextBox ID="uiToLocation" runat="server" Width="100%" AutoPostBack="true"
                    OnTextChanged="uiToLocation_Leave" EmptyMessage="<%$ Resources:ResourceHKEx,Arrive_To %>" />
            </ContentTemplate>
        </asp:UpdatePanel>

    </div>

    <div class="col-md-2 customColumnPadding" id="uiColumnDistance" runat="server">
        <telerik:RadNumericTextBox ID="uiDistance" runat="server" Width="100%" MinValue="0" NumberFormat-DecimalDigits="2" EmptyMessage="<%$ Resources:Resource,Distance %>" />
    </div>

</div>
<div class="hr-line-dashed"></div>

And Here is my code behind: UsageControl2SubControl1.ascx.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace WebControls
{
    public partial class UsageControl2SubControl1 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Convert.ToBoolean(uiRemoved.Value))
            {
                this.Visible = false;
            }
        }

        protected void uiAdd_Click(object sender, Telerik.Web.UI.ImageButtonClickEventArgs e)
        {

        }

        protected void uiRemove_Click(object sender, Telerik.Web.UI.ImageButtonClickEventArgs e)
        {

        }

        protected void RadComboBoxProduct_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {

        }

        protected void uiAdd_Click1(object sender, ImageClickEventArgs e)
        {


        }

        protected void uiRemove_Click1(object sender, ImageClickEventArgs e)
        {

        }

        protected void uiToLocation_Leave(object sender, EventArgs e)
        {


            this.uiDistance.Text = "123";

        }
    }// end class
}// end namespace 
8
  • it triggering when you write something in this field. Do you know it? Commented May 7, 2019 at 6:23
  • Sorry, I am not so sure. Can you explain a little bit? How can I solve the issue? Commented May 7, 2019 at 6:24
  • have you put break point on uiToLocation_Leave event to see does that event triggers? Commented May 7, 2019 at 6:25
  • @want_to_be_calm yes, say me when it have to fired and i will write to you code Commented May 7, 2019 at 6:27
  • @KevinShah , Yes, I put the breakpoint in it and it does run. Commented May 7, 2019 at 6:28

4 Answers 4

1

Just to update your aspx code little bit

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>

<div class="form-group">
    <div class="col-md-2 customColumnPadding">           
         <telerik:RadTextBox ID="uiToLocation" runat="server" Width="100%" AutoPostBack="true"
                    OnTextChanged="uiToLocation_Leave" EmptyMessage="<%$ Resources:ResourceHKEx,Arrive_To %>" />
    </div>

    <div class="col-md-2 customColumnPadding" id="uiColumnDistance" runat="server">
        <telerik:RadNumericTextBox ID="uiDistance" runat="server" Width="100%" MinValue="0" NumberFormat-DecimalDigits="2" EmptyMessage="<%$ Resources:Resource,Distance %>" />
    </div>

</div>
  </ContentTemplate>
        </asp:UpdatePanel>

As your textbox is only inside the update panel so, on post back only that portion is partially updated, you need to put RadNumericTextBox inside the update panel too.

Hope this will work.

Sign up to request clarification or add additional context in comments.

Comments

0

You are using the wrong property. Use Value not Text

protected void uiToLocation_Leave(object sender, EventArgs e)
{
   this.uiDistance.Value = "123";
}

As always, check the documentation. See: https://docs.telerik.com/devtools/aspnet-ajax/controls/numerictextbox/features/getting-and-setting-values

Comments

0

Your current code will works only when you tab out from uiToLocation textbox.

If you want to show it when page loads, just move your code in to Page_Load event instead uiToLocation_Leave.

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Convert.ToBoolean(uiRemoved.Value))
            {
                this.Visible = false;
            }
            this.uiDistance.Text = "123"; // it will assign when page loads.
        }

If you want to load it only once when page loads, use IsPostaback, see below.

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Convert.ToBoolean(uiRemoved.Value))
            {
                this.Visible = false;
            }

            if (!IsPostBack)
            {
                this.uiDistance.Text = "123"; // it will assign only once when page loads.
            }
        }

2 Comments

What I need is I want uiDistance to be updated when I type something in uiToLocation, and I find it after I type in uiToLocation, it does go to uiToLocation_Leave and run this.uiDistance.text = "123", however, I see in the webpage, nothing is changed.
If this is what you want, follow @Kevin Shah's answer. Move your textbox inside update panel.
0

IT seems you are using the wrong property to assign value to telerik Textbox.

Use .Value property as .Text property if for default aspx Textbox control

this.uiDistance.Value= "123"

1 Comment

Please avoid posting duplicate answers. Please see my answer posted 15min before yours

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.