RadNumericTextBox in dynamicaly generated control

3 posts, 0 answers
  1. Zdeněk
    Zdeněk avatar
    27 posts
    Member since:
    May 2007

    Posted 09 Dec 2010 Link to this post

    Hi all,
    could please somebody help me with this problem?
    I have RadNumericTextBox in GridTemplateColumn of RadGrid. I want two things:
    - OnKeyPress it will compute differnce between its value and some start value
    - OnValueChanged it will update value in database (through AJAX call)

    ASPX page snippet:
    <telerik:GridTemplateColumn UniqueName="colValue" HeaderText="Stav" ItemStyle-Width="35px">
            ID="txtCounterValue" runat="server"  Width="80"
            MinValue="0" NumberFormat-AllowRounding="false" NumberFormat-DecimalDigits="0"
            EnabledStyle-HorizontalAlign="Right" EnabledStyle-Font-Bold="true"
            <ClientEvents  OnKeyPress="CounterKeyPress"OnValueChanged="CounterValueChanged"  />
      <div id="txtStartValue" runat="server" ></div>
        <div id="txtDifference" runat="server" ></div>

    Snippet of code-behind:
    Protected Sub rgDeviceCountersDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)
                Dim myCounter = DirectCast(e.Item.DataItem, Data.DeviceCounter)
                Dim txtCounterValue As RadNumericTextBox = DirectCast(e.Item.FindControl("txtCounterValue"), RadNumericTextBox)
    txtCounterValue =myCounter.StartValue
                Dim txtStartValue As HtmlGenericControl = DirectCast(e.Item.FindControl("txtStartValue"), HtmlGenericControl)
                Dim txtDifference As HtmlGenericControl = DirectCast(e.Item.FindControl("txtDifference"), HtmlGenericControl)
            End Sub

    Snippet of javascript:
    var ajaxManager;
    function pageLoad() {
    ajaxManager = $find("<%=RadAjaxManager.GetCurrent(Page).ClientID %>");

    function CounterKeyPress(sender, eventArgs) {
                    /* update InnerText of txtDifference with difference between RadNumericTextBox andtxtStartValue */
    /* HOW TO ACHIEVE THIS? :-) */

    CounterValueChanged(sender, eventArgs) {
                    /* Count difference betweentxtStartValue and txtCounterValue and call AJAX update of record (how to get Primary Id from ClientDataKeyNames?) */
    ajaxManager.ajaxRequest(... AND WHAT HERE ...?);

    Thank you very much for your help!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Dec 2010 Link to this post

    Hello Zdenek Plachy ,

    Try the following approach .
     In 'OnKeyPress' event of RadNumericTextBox invoke the ajaxRequest and pass the row index to server side. In AjaxManager_AjaxRequest server event, you can access the corresponding cell value and perform the calculation. You can do the same using 'OnValueChanged' event and perform updation on server side.

    The following forum shows how to fing the row index from client side.
    Get grid's row index of valueChanged radTextBox

    And check out the following documentation for accessing cells and rows in RadGrid.
    Accessing cells and rows
  3. Zdeněk
    Zdeněk avatar
    27 posts
    Member since:
    May 2007

    Posted 10 Dec 2010 Link to this post

    Thank you very much!
    Meanwhile I made it completely client side. For database update I wrote my own XMLHttpRequest, calling other aspx page, where database logic make the rest.

    Next time I will wrestle with AJAX your (and correct) way :-)
Back to Top