[RESOLVED]clear textbox with different id

Hi,

I have asp.net textboxes width different IDs.

I would like to add linkbutton that will clear all textboxes in the page dynamically.

or other option is to clear all the asp.net form, think it should be easier.

How can I do that?

Hi

Checkout the post below. From javascript you can reset the form as follows:

document.forms[0].reset();

http://forums.asp.net/t/1015988.aspx?Need+help+with+ASP+NET+Reset+button+to+clear+form+fields+non+html+button+

http://www.dotnetcurry.com/showarticle.aspx?ID=78

may be you can try out this,

 $(‘#form_id :text).val(”);

Hi borisre,

Thanks for your post.

borisre

I would like to add linkbutton that will clear all textboxes in the page dynamically.

As for your problem, you could refer to the following sample to empty TextBoxes.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../../Scripts/jquery-1.8.2.js"></script>
    <script>
        $(function () {
            $("#BtnClean").click(function () {
                $("input[type=text]").val("");
                return false;
            })
        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
        <br />
        <asp:LinkButton ID="BtnClean" runat="server">Clean</asp:LinkButton>
    </div>
    </form>
</body>
</html> 

If you have any question  about this issue, please post back freely.

Best Regards,

Fei Han

thanks, it worked great, but I keep on getting the following error after using it:

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback
or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Leave a Reply