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

Alert when value changed in TextBox

2 Answers 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 29 Jan 2009, 08:47 PM
I have a RadGrid which has a RadNumericTextBox in each row.  What I am looking for is a way to show an alert if a user changes the value in the TextBox.  What would be in your opinion the best way to accomplish this?

Thank You!

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Jan 2009, 05:17 AM
Hi Mike,

One suggestion to achieve this scenario is by attaching onfocus and onblur handlers for RadNumericTextBox and check the value inside the client side function to show alert if the value differs.

CS:
protected void RadGrid1_ItemDataBound1(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem) 
    { 
        RadNumericTextBox textbox = e.Item.FindControl("Number"as RadNumericTextBox; 
        textbox.Attributes.Add("onblur""return show(" + textbox.ClientID + ")"); 
        textbox.Attributes.Add("onfocus""return getvalue(" + textbox.ClientID + ")"); 
    } 

JavaScript:
<script type="text/javascript"
var value; 
function show(arg) 
    if(value!=arg.value) 
    alert("Value Changed"); 
function getvalue(arg) 
    value= arg.value; 
</script> 

ASPX:
<telerik:GridTemplateColumn UniqueName="TemplateColumn"
    <ItemTemplate> 
         <telerik:RadNumericTextBox ID="Number" runat="server"></telerik:RadNumericTextBox> 
    </ItemTemplate> 
</telerik:GridTemplateColumn> 

Thanks,
Shinu.
0
Mike
Top achievements
Rank 1
answered on 30 Jan 2009, 01:29 PM
I ended up doing this and it works like a charm.  
 <telerik:GridTemplateColumn HeaderText="Avg. Contract Price per kWh" HeaderStyle-VerticalAlign="Top" ItemStyle-HorizontalAlign="Center" > 
   <ItemTemplate> 
    <telerik:RadNumericTextBox ID="TextBoxPrice1" NumberFormat-DecimalDigits="4" Height="0" Width="0" Visible="true" CssClass="hide" runat="server" /> 
    <telerik:RadNumericTextBox ID="TextBoxPrice2"                                                                                        
                               Type="Currency"    
                               NumberFormat-DecimalDigits="4"         
                               EnabledStyle-Font-Size="8pt"   
                               EnabledStyle-HorizontalAlign="Right"   
                               EnabledStyle-Font-Names="Arial"   
                               MaxLength="9"   
                               Height="9"   
                               Width="50"   
                               runat="server">    
    </telerik:RadNumericTextBox> 
    <asp:CompareValidator id="CompareValidator1" 
                          Text="Changed!" 
                          ControlToValidate="TextBoxPrice1" 
                          ControlToCompare = "TextBoxPrice2"     
                          Type = "String"        
                          Operator="Equal"                                                        
                          Runat="server"/>           
  </ItemTemplate> 
 </telerik:GridTemplateColumn>   
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Share this question
or