Search code examples
jqueryasp.netvb.netformview

Formview & Listview Update dataset on TextChange tab out


I have a formview and a listview that each have a textbox called "Grade_CodeTextbox" in the edit template. Instead of editing the data in the textbox and clicking an Update button to save changes back to the SQLDatasource, I'd like to save the update on the textbox textchange when the user tabs out of the Grade_Codetextbox. Is this possible? And if so, can someone help me with a small example? Thank you in advance!

<EditItemTemplate>
    <span style="">ID:
    <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
    <br />
    Class_ID:
    <asp:TextBox ID="Class_IDTextBox" runat="server" Text='<%# Bind("Class_ID") %>' />
    <br />
    Assignment_ID:
    <asp:TextBox ID="Assignment_IDTextBox" runat="server" Text='<%# Bind("Assignment_ID") %>' />
    <br />
    Student_ID:
    <asp:TextBox ID="Student_IDTextBox" runat="server" Text='<%# Bind("Student_ID") %>' />
    <br />
    Grade_Code:
    <asp:TextBox ID="Grade_CodeTextBox" runat="server" AutoPostBack="True" Text='<%# Bind("Grade_Code") %>' />
    <br />
    Comment:
    <asp:TextBox ID="CommentTextBox" runat="server" Text='<%# Bind("Comment") %>' />
    <br />
    <asp:CheckBox ID="ExemptCheckBox" runat="server" Checked='<%# Bind("Exempt") %>' Text="Exempt" />
    <br />
    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
    <br />
    <br />
    </span>
</EditItemTemplate>

Solution

  • Yes, it's possible to do what you mentioned in your question.

    To implement your requirement you will need to add code as mentioned below.

    1. Subscribe to TextChanged server-side event for the textbox. The markup should look like below. Note the OnTextChangedproperty that I have included in the markup.

    Markup for TextChanged event

    <asp:TextBox ID="Grade_CodeTextBox" runat="server" AutoPostBack="True"
          Text='<%# Bind("Grade_Code") %>'  OnTextChanged="Grade_CodeTextBox_TextChanged"  />
    
    1. Write code for the server-side event subscribed to in above step.

    Server-side code in VB.Net

    Protected Sub Grade_CodeTextBox_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
     'Write your code here when text changes in this textbox
     'For example, you could save textbox text in database
    
    End Sub