From what I have been seeing the function isn't event called. This is what I got working:
Markup:
<asp:textbox id="txtfname" runat="server" />
<asp:textbox id="txtlname" runat="server" />
<asp:button id="clear" runat="server" text="clear" causesvalidation="false"
BackColor="#FF8000" Font-Bold="True"
OnClientClick="return clearTextBoxes(this.id)" />
</asp:button>
A few things to note here:
1. I changed the name of the function. This is because if I were to change it to "clear" the function would not be called. I'm guessing due to a naming conflict.
2. I return the return value of the function.
3. I am passing the function the id of the button. This is to obtain the element ids using javascript instead of ASP.
JavaScript:
function clearTextBoxes(btnId) {
var selector = btnId.replace("clear", "txtfname");
var fname = document.getElementById(selector);
selector = btnId.replace("clear", "txtlname");
var lname = document.getElementById(selector);
fname.value = "";
lname.value = "";
return true;
}
Here I create the id of the first textbox to use in getElementById. Then I get a local variable containing the first textbox. The same thing is done for the second textbox. After the textboxes are obtained, clearing can commence. Finally I return true. Returning "false" instead would keep from a post back. Returning "true" keeps the post back.