Click here to Skip to main content
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 21: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 Sergey Alexandrovich Kryukov 9,455
1 OriginalGriff 8,295
2 Peter Leow 4,839
3 Kornfeld Eliyahu Peter 3,210
4 Maciej Los 2,301


Advertise | Privacy | Mobile
Web04 | 2.8.150327.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