Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Guys,

i am facing one problem.
XML
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function check() {
            var completion = 0;
            if (document.getElementById("field1").value != "") {
                completion++;
            }
            if (document.getElementById("field2").value != "") {
                completion++;
            }
            if (document.getElementById("field3").value != "") {
                completion++;
            }
            document.getElementById("progressbar").style.width = completion * 20 + "px";
        }
</script>
</head>
<body>
    <form id="form1" action="Temp1.aspx" runat="server">
    <div>
     Name: <input type="text" id="field1" onchange="check()" /><br />
    Tel No.: <input type="text" id="field2" onchange="check()" /><br />
    Email: <input type="text" id="field3" onchange="check()" /><br />
    Completion: <div style="width: 60px; height: 10px; border: 1px solid black;">
        <div style="width: 0px; height: 10px; background-color: green;" id="progressbar">&nbsp;</div>
    </div>
    <input type="submit" />
    </div>
    </form>
</body>
</html>

above html code working fine and showing progress bar,but for asp.net code it is not working,please help me.
XML
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function check() {
            var completion = 0;
            if (document.getElementById("field1").value != "") {
                completion++;
            }
            if (document.getElementById("field2").value != "") {
                completion++;
            }
            if (document.getElementById("field3").value != "") {
                completion++;
            }
            document.getElementById("progressbar").style.width = completion * 20 + "px";
        }
    </script>
</head>
<body>
    <form id="form1" action="Temp.aspx" runat="server">
    <div>
        <table style="width: 100%;">
            <tr>
                <td>
                    &nbsp;
                </td>
                <td>
                    <asp:TextBox ID="field1" runat="server" OnTextChanged="check()" ></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td>
                    <asp:TextBox ID="field2" runat="server" OnTextChanged="check()"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td>
                    <asp:TextBox ID="field3" runat="server" OnTextChanged="check()"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td>
                    <asp:TextBox ID="field4" runat="server" OnLoad="check()"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Completion:
                    <div style="width: 60px; height: 10px; border: 1px solid black;">
                        <div style="width: 0px; height: 10px; background-color: green;" id="progressbar">
                            &nbsp;</div>
                    </div>
                    <input type="submit" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
Posted
Updated 25-Jan-13 3:03am
v2

1 solution

You need to add a client-side handler for your asp:TextBox controls. The OnTextChanged handler runs server side.

In other words. the code will try to perform a check function in your code behind.
 
Share this answer
 
v3

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