Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Clear textboxes with gridview display

$
0
0

Hello,

I am using update panels to display some textboxes. The textboxes are filled in and a button click event is fired that inserts the textbox data into the sql database that is bound to a gridview.

I am able to insert the values into the database and gridview just fine but am unable to clear the textboxes without it stopping the gridview from appearing.

I have tried setting the textbox values to "" and string.empty but think it must be something else causing the problem, any ideas?

.CS

protected void MyButtonSave_Click(object sender, EventArgs e)
        {
            SqlDataSourceNwd.Insert();
            GridView1.DataBind();
            System.Threading.Thread.Sleep(2000);
            MyTextBoxCity.Text = "";
            MyTextBoxCompany.Text = "";
            MyTextBoxContact.Text = "";
            MyTextBoxPhone.Text = "";
        }

Default

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <div style="margin: 20px 0px 20px 40px">
                        Company<br />
                        <asp:TextBox ID="MyTextBoxCompany" runat="server" Width="200"></asp:TextBox>
                        <br />
                        Contact Name<br />
                        <asp:TextBox ID="MyTextBoxContact" runat="server" Width="200"></asp:TextBox>
                        <br />
                        City<br />
                        <asp:TextBox ID="MyTextBoxCity" runat="server" Width="200"></asp:TextBox>
                        <br />
                        Phone<br />
                        <asp:TextBox ID="MyTextBoxPhone" runat="server" Width="200"></asp:TextBox>
                        <br />
                        <asp:Button ID="MyButtonSave" runat="server" Text="add" Style="margin-top: 15px"
                            OnClick="MyButtonSave_Click" />
                    </div>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger EventName="Click" ControlID="MyButtonSave" />
                </Triggers>
            </asp:UpdatePanel>
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                DataKeyNames="SupplierID" DataSourceID="SqlDataSourceNwd" Visible="true">
                <Columns>
                    <asp:BoundField DataField="SupplierID" HeaderText="SupplierID" InsertVisible="False"
                        ReadOnly="True" SortExpression="SupplierID" />
                    <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
                    <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />
                    <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                    <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSourceNwd" runat="server" ConnectionString="<%$ ConnectionStrings:NwdConnectionString %>"
                SelectCommand="SELECT [SupplierID], [CompanyName], [ContactName], [City], [Phone] FROM [Suppliers] ORDER BY [CompanyName]"
                InsertCommand="INSERT INTO Suppliers(CompanyName, ContactName, City, Phone) VALUES (@Company,@Contact,@City,@Phone)">
                <InsertParameters>
                    <asp:ControlParameter ControlID="MyTextBoxCompany" Name="Company" PropertyName="Text" />
                    <asp:ControlParameter ControlID="MyTextBoxCity" Name="City" PropertyName="Text" />
                    <asp:ControlParameter ControlID="MyTextBoxContact" Name="Contact" PropertyName="Text" />
                    <asp:ControlParameter ControlID="MyTextBoxPhone" Name="Phone" PropertyName="Text" />
                </InsertParameters>
                <SelectParameters>
                    <asp:ControlParameter ControlID="MyTextBoxCompany" Name="Company" PropertyName="Text" />
                    <asp:ControlParameter ControlID="MyTextBoxCity" Name="City" PropertyName="Text" />
                    <asp:ControlParameter ControlID="MyTextBoxContact" Name="Contact" PropertyName="Text" />
                    <asp:ControlParameter ControlID="MyTextBoxPhone" Name="Phone" PropertyName="Text" />
                </SelectParameters>
            </asp:SqlDataSource>
            <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                <ProgressTemplate>
                    <div style="margin-top: 20px; font-size: larger; color: Green">
                        Processing, please wait ...
                    </div>
                </ProgressTemplate>
            </asp:UpdateProgress>
        </ContentTemplate>
    </asp:UpdatePanel>





Viewing all articles
Browse latest Browse all 5678

Trending Articles