Text value of RadTimePicker control

6 posts, 1 answers
  1. Markus Jansson
    Markus Jansson avatar
    5 posts
    Member since:
    Dec 2008

    Posted 26 Nov 2009 Link to this post

    Hi!

    Just a simple question. How do I get the text value of a RadTimePicker control in the code behind? I have searched for it but can't seem to find it. There is a DateInput.Text property but that doesn't show the text written. I must be able to distinguish between an empty control and an invalid one. So, if someone for example writes "xyz" into the control, where do I find this value?

    Thanks!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Nov 2009 Link to this post

    Hi Markus Janson,

    I tried following code in order to get the text typed by user evenif its is invalid and found it is working fine for me.
         string str1 = RadTimePicker1.DateInput.Text.ToString();

    Another option is getting the typed value (which is invalid) from client side and saving in a HiddenField control, so that you can check from the code behind.
    aspx:
     
        <telerik:RadTimePicker ID="RadTimePicker1" runat="server"
            <DateInput> 
                <ClientEvents OnError="OnError" /> 
            </DateInput> 
        </telerik:RadTimePicker> 
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Get the Text" /> 
            <asp:HiddenField ID="HiddenField1" runat="server" /> 

    javascript:
     
    <script type="text/javascript"
        function OnError(sender, args) { 
            alert("Invalid Date   :" + args.get_inputText()); 
            document.getElementById("HiddenField1").value = args.get_inputText(); 
        }  
    </script> 

    cs:
     
    string temp = HiddenField1.Value; 

    -Shinu.
  3. Dimo
    Admin
    Dimo avatar
    8452 posts

    Posted 26 Nov 2009 Link to this post

    Hi Markus,

    You can obtain the invalid content of the DateInput textbox server-side like this:

    RadTimePicker1.DateInput.ValidationDate


    Kind regards,
    Dimo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  4. Markus Jansson
    Markus Jansson avatar
    5 posts
    Member since:
    Dec 2008

    Posted 26 Nov 2009 Link to this post

    Hi both Shinu and Dimo and thanks for quick responses!

    However I'm afraid none of the code behind properties (haven't tried the one including client side yet) seem to work, at least not for me. If I make a simple page with this aspx:

    <body> 
        <form id="form1" runat="server">  
        <div> 
            <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">  
            </telerik:RadScriptManager> 
            <br /> 
            <telerik:RadTimePicker ID="RadTimePicker1" Runat="server">  
            </telerik:RadTimePicker> 
            <br /> 
            <asp:Button ID="Button1" runat="server" Text="Button" /> 
            <br /><br /> 
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
            <br /> 
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> 
        </div> 
        </form> 
    </body> 
     

    and this VB:

        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click  
            TextBox1.Text = RadTimePicker1.DateInput.Text.ToString  
            TextBox2.Text = RadTimePicker1.DateInput.ValidationDate  
        End Sub  
     

    and then run the page, enter an invalid time, like "xyz", and click the button, the textboxes remain empty.

    Do you get a different result with the same code and, if so, why?

    Regards,
    Markus
  5. Answer
    Dimo
    Admin
    Dimo avatar
    8452 posts

    Posted 26 Nov 2009 Link to this post

    Hello Markus,

    The method I suggested will work with RadControls Q3 2009 (2009.3.1103) and later versions. For earlier versions the only way to find out what the user has entered inside the textbox is to examine the array of posted values and look for the following key:

    Request.Params("RadTimePicker1_dateInput_text")


    Regards,
    Dimo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Markus Jansson
    Markus Jansson avatar
    5 posts
    Member since:
    Dec 2008

    Posted 27 Nov 2009 Link to this post

    Hi Dimo,

    I tried upgrading to Q3 but ran into some problems in other areas so I went back to Q2.

    Anyway the other solution you suggested (Request.Params) worked like a charm so I'm happy now.

    Many thanks!

    Regards,
    Markus
Back to Top