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

Postback on OnTextChanged

2 Answers 197 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manikandan Balasubramaniyan
Top achievements
Rank 1
Manikandan Balasubramaniyan asked on 02 Sep 2010, 08:18 PM
Hi,

I am trying to dynamically add the values entered in the cells and populate the total in another Cell.  So i call total() function onTextChange in each texbox within the Grid. The entire grid postbacks, this will be annoying to the user. I need a funcationality similar to Excel where one cell holds the formula to add the values in required cells.      I have pasted the code snippet here below just for testing purpose, i tried to populate one textbox with the value of other and checking the onTextChange event in each textbox within the grid.                     
Please let me know what needs to be fixed so that the entire page doesnot postbacks, the total value is automatically added.

<telerik:RadGrid ID="RadGrid1" runat="server" Skin="" AutoGenerateColumns=false>
                                        <MasterTableView DataKeyNames="WEB_ACCOUNT_ID,WEB_PER_ID,WEEK_ID,DETAIL_ID">
                                            <Columns>                                               
                                                <telerik:GridTemplateColumn UniqueName="TemplateColumn">
                                                    <ItemTemplate>
                                                        <asp:TextBox ID="txt_sun_hrs" runat="server" Text='<%# Eval("SUN_HRS") %>' Width="90%"
                                                            MaxLength="4" OnTextChanged="textBox_TextChangedRad" AutoPostBack=true>   </asp:TextBox>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
                                                <telerik:GridTemplateColumn UniqueName="TemplateColumn">
                                                    <ItemTemplate>
                                                        <asp:TextBox ID="txt_mon_prem" runat="server" Text='<%# Eval("MON_PREM") %>' Width="90%"
                                                            MaxLength="4" OnTextChanged="textBox_TextChangedRad" AutoPostBack=true></asp:TextBox>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
                                            </Columns>
                                        </MasterTableView>
                                    </telerik:RadGrid>

CodeBehind:
    protected void textBox_TextChangedRad(object sender, System.EventArgs e)
    {
        int start, end, updatedrow;
        double sun_Hrs, mon_prem;
        TextBox txtHrs = ((TextBox)(sender));
      
        GridDataItem item = (GridDataItem)txtHrs.NamingContainer;        
       
        sun_Hrs = Convert.ToDouble(((TextBox)item.FindControl("txt_sun_hrs")).Text.Equals("") ? "0" : ((TextBox)item.FindControl("txt_sun_hrs")).Text.ToString());

        ((TextBox)item.FindControl("txt_mon_prem")).Text = sun_Hrs.ToString();

    }

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 03 Sep 2010, 10:37 AM
Hello Manikandan,

If you want to avoid post-back on TextChanged event, try to do this in client side. For that attach 'onfocusout' event to the first textboxe from code behind and pass the id of second textbox to the event handler. Then in the event handler, it is possible to calculate the result and assign the value to second textbox.

Also refer the following forum post.
Change Cell value?

Hope this information helps,
Princy.
0
Manikandan Balasubramaniyan
Top achievements
Rank 1
answered on 07 Sep 2010, 01:33 PM
Thank you.
Tags
Grid
Asked by
Manikandan Balasubramaniyan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Manikandan Balasubramaniyan
Top achievements
Rank 1
Share this question
or