Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
Don’t be run my script by click html control
HI'
In vs2010 I put a html control (bottun) on page . and defined a function of javascript for it. And set the necessary things in <input ….>
1- In design whenever I click the bottun the new function will create
2- In design , by every double click on bottun, the onload="func_name()" will added to end of In <input …> therefor there will be write many onloald at end of <input ..>
3- When I delete unnecessary onload and body of extra function, and run the site and click the bottun , it willn't work.
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="script4.aspx.cs" Inherits="WebApplication1.script4" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">


        function reset_onclick() {
            //document.write("JJJJJJJJJJJJJJJ");
            document.forms[0].reset();
            return false;
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        &nbsp;<input id="Text1" type="text" value="TEST FOR CLEAR" />&nbsp;&nbsp;&nbsp;&nbsp;
        <input id="Checkbox1" checked="checked" type="checkbox" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input id="Radio1" checked="checked" type="radio" /><br />
        <br />

        <input id="reset" type="button" value="reset" onclick="return reset_onclick()" />
        <br />
        <asp:Button ID="MyResetButton" runat="server" onclick="Button1_Click"
            Text="MyResetButton" />

     </div>
    </form>
</body>
</html>
Posted
Updated 14-May-11 21:48pm
v3

1 solution

Dear Friend,

I changed you code little bit. Its working fine now. copy paste this code , it will work

MSIL
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="script4.aspx.cs" Inherits="WebApplication1.script4" %>


XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>

    <script language="JavaScript">
        function resetForm() {
            document.getElementById("userForm").reset();
        }
    </script>

    <form id="userForm" runat="server">
    <input id="Text1" type="text" value="TEST FOR CLEAR" />
    <input id="Checkbox1" checked="checked" type="checkbox" />
    <input id="Radio1" checked="checked" type="radio" />
    <br />
    <input type="button" value="Reset all fields" onclick="resetForm()" />
    <br />
    <asp:Button ID="MyResetButton" runat="server" OnClick="Button1_Click" Text="MyResetButton" />
    </form>
</body>
</html>




Regards,
Sabindas
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900