I am needing to use a javascript function to total 5 textboxes as the user types in a money value all within the EditForm template.Normally I just view the source of the web page to grab the funky name that asp.net gives controls but I cannot see the source of the Edit template. My function needs the names of the textboxes to work. Has anyone done this?
Thanks,
Sam
Thanks,
Sam
4 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 07 Aug 2009, 06:52 AM
Hi Sam,
One easy way to achieve this functionality is adding onclick event from code behind so that it is possible to pass the textbox ClientID to client-side and then calculate the total amount there. See the example shown below.
ASPX:
C#:
JavaScript:
-Shinu.
One easy way to achieve this functionality is adding onclick event from code behind so that it is possible to pass the textbox ClientID to client-side and then calculate the total amount there. See the example shown below.
ASPX:
| <EditFormSettings EditFormType="Template"> |
| <FormTemplate> |
| <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> |
| <br /> |
| <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> |
| <br /> |
| <asp:Button runat="server" ID="Button1" Text="Total" /> |
| </FormTemplate> |
| </EditFormSettings> |
C#:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridEditFormItem && e.Item.IsInEditMode) |
| { |
| GridEditFormItem item = (GridEditFormItem)e.Item; |
| TextBox textbox1 = (TextBox)item.FindControl("TextBox1"); |
| textbox1.Text = "1234"; |
| TextBox textbox2 = (TextBox) item.FindControl("TextBox2"); |
| Button btn = (Button)item.FindControl("Button1"); |
| btn.Attributes.Add("onclick","calc('"+ textbox1.ClientID+"','"+textbox2.ClientID+"'"+");return false;"); |
| } |
| } |
JavaScript:
| <script type="text/javascript"> |
| function calc(t1, t2) |
| { |
| var result = (+document.getElementById(t1).value) + (+document.getElementById(t2).value); |
| alert(result); |
| } |
| </script> |
-Shinu.
0
Sam
Top achievements
Rank 1
answered on 07 Aug 2009, 01:20 PM
Thanks,
The only issue I see with that solution is I need to update the value of a label in the edit template with the total from the textboxes and I run into the issue of not knowing the name of the label control in javascript.
The only issue I see with that solution is I need to update the value of a label in the edit template with the total from the textboxes and I run into the issue of not knowing the name of the label control in javascript.
0
Sam
Top achievements
Rank 1
answered on 10 Aug 2009, 04:14 PM
Does anyone know the naming convention for the EditTemplates controls??? I need to update the value in a label inside of the edit template with javascript.
0
Sam
Top achievements
Rank 1
answered on 11 Aug 2009, 01:22 PM
Anyone?????? I am at a stopping point on this and need it to work in more areas than one.