Click here to Skip to main content
12,246,406 members (44,264 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Hi Guys,

i am facing one problem.
<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.
<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 25-Jan-13 2:51am
Edited 25-Jan-13 4:03am
V.50.4K
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v3

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100