Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,

I am trying to hide textbox on click of Server control. But seems like its not working

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js">
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#btnSubmit1").click(function () { $("#txtbox1").hide(); });
    });

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p>
            <input id="txtbox1" type="text" />
        </p>
        <asp:Button ID="btnSubmit1" Text="test34" runat="server" />

    </div>
    </form>
</body>
</html>


Any suggestions ?
Posted

1 solution

change your code
$(document).ready(function () {
    $("#btnSubmit1").click(function () { $("#txtbox1").hide(); });
});


with this code

JavaScript
$(document).ready(function () {
          $($get('<%= btnSubmit1.ClientID %>')).click(function () { $("#txtbox1").hide(); });
      });


you must to add your page scriptmanager control in i a serverside form because of getting serverside controls in javascript code block.
XML
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
    <div>
        <p>
            <input id="Text1" type="text" />
        </p>
        <asp:Button ID="btnSubmit1" Text="test34" runat="server" />

    </div>
    </form>



but this isnt best solution for what you want to do. Serverside buttons will create a post from client to server. when you clicked your buttons it will hide your inputs but after post you will see it doesnt effect.
my advice only about calling a serverside control from javascipt. your way doesnt a good way for hiding any control.
 
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