locked
How to Change the Value of Label and Display a Div RRS feed

  • Question

  • User1945137292 posted

    Hi Friends, I have designed a page to register employee.

    Please go through the code of Page: -

    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
        <script src="javascripts/jquery-1.7.1.min.js" type="text/javascript"></script>
        <script src="javascripts/jquery.hashchange.js" type="text/javascript"></script>
        <script src="javascripts/jquery.easytabs.js" type="text/javascript"></script>
        <link rel="Stylesheet" href="css/css/button.css" />
        <link rel="Stylesheet" href="css/menu.css" />
        <link rel="Stylesheet" href="css/base.css" />
        <link rel="Stylesheet" href="css/etab.css" />
        <%--<script src="js/jquery-1.11.1.min.js" type="text/javascript"></script>--%>   
        <!--Responsive-->
        <meta name="viewport" content="width=device-width, initial-scale=1"/>   
        <!--Responsive-->
        <script type="text/javascript">
            function PrintThis() {
                document.getElementById("RegisterEmp").style.display = "none";
                document.getElementById("btnPrint").style.display = "none";
                document.title = 'Employee Registration Number';
                window.print();
                document.getElementById("RegisterEmp").style.display = "block";
                document.getElementById("btnPrint").style.display = "block";
            }
    </script>
        <script type="text/javascript">
            function register() {
                var name = document.getElementById("txtName").value;
                var gender = document.getElementById("ddlGender").value;
                var dob = document.getElementById("txtDOB").value;
                var mobile = document.getElementById("txtMobile").value;
                var url = "registerEmp.aspx?name=" + name + "&gender=" + gender + "&dob=" + dob + "&mobile=" + mobile;
                //alert(url);
                var search = new XMLHttpRequest();
                search.open("get", url, true);
                search.onreadystatechange = function () { f2(search); };
                search.send(null);
            }
            function f2(search) {
                if (search.readyState != 4)
                    return;
                var id = search.responseText;
                $('#lblMessage').val('Registration Successfull.');
                $('#PrintReg').show(); $('#lblRegNo').val(id);
                //document.getElementById("lblMessage").innerHTML = "Registration Successfull.";
                //document.getElementById("PrintReg").style.display = "block";
                //document.getElementById("lblRegNo").innerHTML = id;
            }
        </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        
        <div class="tab-container" id="outer-container">
            <ul class='etabs'>
                <li class='tab'><a href="#Add_Admin">Add Admin</a></li>
                <li class='tab'><a href="#Add_Employee">Add Employee</a></li>
                <li class='tab'><a href="#nested-tab-3">Contains more tabs</a></li>
            </ul>
            <div class="panel-container">
                <div id="Add_Admin">
                    <h2>Heading 1</h2>
                    <p>This is the content of the first tab.</p>
                </div>
                <div id="Add_Employee">
                    <div class="tab-container" id="inner-container-emp">
                        <ul class='etabs'>
        <li class='tab'><a href="#Register_Employee">Register Employee</a></li>
        <li class='tab'><a href="#Create_Login_ID">Create Log-in ID</a></li>
      </ul> <br /> <br />
      <div id="Register_Employee" style="text-align:left;">     
        <!--Contact Form-->  <br />    
        <div id="RegisterEmp">
            <form method="get" onsubmit="register()">
            <table>
                <tr>
                    <td><input type="text" id="txtName" name="txtName" class="tb" required placeholder="Name *" title="Employee Name"/></td>
                </tr>
    
                <tr><td><br /></td></tr>
    
                <tr>
                    <td><select id="ddlGender" class="ddl" required title="Employee Gender">
        <option value="Male" title="Male">Male</option>
        <option title="Female" value="Female">Female</option>
        </select></td>
                </tr>
    
                <tr><td><br /></td></tr>
    
                <tr>
                    <td><input id="txtDOB" class="tb" required type="text" pattern="\d{1,2}-\d{1,2}-\d{4}" placeholder="Date of Birth *" title="DD-MM-YYYY"/></td>
                </tr>
    
                <tr><td><br /></td></tr>
    
                <tr>
                    <td><input id="txtMobile" class="tb" required placeholder="Mobile *" type="tel" pattern="^\d{2}-\d{10}$" title="Write like 91-xxxxxxxxxx"/></td>
                </tr>
    
                <tr><td><br /></td></tr>
    
                <tr>
                    <td><input type="submit" class="myButton" id="btnSave" title="Save" value="Save"/></td>
                </tr>
    
                <tr><td><br /></td></tr>
    
                <tr>
                    <td><label id="lblMessage">hello!!</label></td>
                </tr>
            </table> 
                </form> 
            </div>  
        
        <div id="PrintReg" style="display:none;">
            <table>
                <tr><td colspan="2">Please Keep Safe Your Registration Number!!</td></tr>
                <tr>
                    <td>Registration No. is: </td>
                    <td><label id="lblRegNo" style="text-transform:lowercase;"></label></td>
                </tr>
                <tr><td colspan="2"><input type="button" class="myButton" value="Print" title="Print" id="btnPrint"  onclick="PrintThis()" /></td></tr>
            </table>    
        </div>
        <!-- content -->
        
      </div>  
      <div id="Create_Login_ID">
        <p style="color:#ffffff;font-size:1.2em; font-weight:normal; font-family:Consolas;float:left; font-style: normal;"></p>  
        <!-- content --> 
            <iframe src="LoginID.aspx" width="900px" frameborder="0" height="500px" scrolling="no"></iframe> 
            <!-- content --> 
      </div>
                    </div>
                </div>
                <div id="nested-tab-3">
                    <h2>Heading 3</h2>
                    <p>More stuff from the last tab.</p>
    
                    <div class="tab-container" id="inner-container">
                        <ul class='etabs'>
                            <li class='tab'><a href="#tab-a">Subtab A</a></li>
                            <li class='tab'><a href="#tab-b">Subtab B</a></li>
                            <li class='tab'><a href="#tab-c">Subtab C</a></li>
                        </ul>
                        <div class="panel-container">
                            <div id="tab-a">
                                <h3>Heading A</h3>
                                <p>This is a nested first tab</p>
                            </div>
                            <div id="tab-b">
                                <h3>Heading B</h3>
                                <p>This is a nested second tab</p>
                            </div>
                            <div id="tab-c">
                                <h3>Heading C</h3>
                                <p>This is a nested third tab</p>
                            </div>
                        </div>
                        <br />
                    </div>
                </div>
            </div>
        </div>
    
        <script type="text/javascript">
            $('#outer-container, #inner-container, #inner-container-emp').easytabs();
        </script>
    </asp:Content>

    code of registerEmp.aspx is given below: -

     protected void Page_Load(object sender, EventArgs e)
        {
            string name= Request.QueryString["name"];
            string gender = Request.QueryString["gender"];
            string dob = Request.QueryString["dob"];
            string mobile = Request.QueryString["mobile"];
            string result = Utility.RegisterEmployee(name, gender, dob, mobile);
            Response.Write(result);        
        }

    With the help of this code my data is being saved to database but I am unable to get the "Employee Registration Number", which is coming form "registerEmp.aspx" page. i.e. Response.Write(result);

    As You see the code, I wanted to display my hidden div "PrintReg" after the successfull registration of employees. and Registration number should also be printed against HTML Label.

    But Unable to do all these.

    If there is any other best way possible to do all these things, then please suggest me.

    But also give the suggestion to do all the things.

    Thank You.

    Monday, April 13, 2015 3:04 PM

All replies

  • User1711366110 posted

    As You see the code, I wanted to display my hidden div "PrintReg" after the successfull registration of employees. and Registration number should also be printed against HTML Label.But Unable to do all these.
    If there is any other best way possible to do all these things, then please suggest me

      As per this case, You need the return so the true/false gets passed up to the form's submit event (which looks for this and prevents submission if it gets a false).
    so you can do like below :

    <form method="get" onsubmit="return register()">
    

    javascript :

    <script type="text/javascript">
    function register() {
            ...
            return ...;
    }
    </script>

    for more information, Click here to refer the similar thread

    --
    with regards,
    Edwin

    Tuesday, April 14, 2015 4:52 AM
  • User1945137292 posted

    Thanks Mr. "Edwin Guru Singh",

    Actually My code is generating Employee code and also records are being saved in to database.

    Actually Look at this code: -

    <tr>
        <td><input type="submit" class="myButton" id="btnSave" title="Save" value="Save"/></td>
    </tr>

    When I changed my button type to "submit" then this problem started.

    Before this I was using "button" type.

    then I was getting all things done according to me.

    But then my required field validator was not working.

    Tuesday, April 14, 2015 12:21 PM
  • User1945137292 posted

    Hello friends, please suggest the way to solve this problem.

    Thursday, April 30, 2015 2:12 PM