Click here to Skip to main content
11,577,643 members (64,478 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET jQuery
Hello,

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

<%@ 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 31-Aug-12 20:17pm

1 solution

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

Solution 1

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

with this code

$(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.
<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.
  Permalink  

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

  Print Answers RSS
0 Peter Leow 180
1 DamithSL 150
2 OriginalGriff 135
3 Richard MacCutchan 135
4 Abhinav S 90
0 OriginalGriff 830
1 Sergey Alexandrovich Kryukov 701
2 Abhinav S 573
3 F-ES Sitecore 420
4 Dave Kreskowiak 374


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 1 Sep 2012
Copyright © CodeProject, 1999-2015
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