Community discussion forum

CLEAR A TEXTBOX on SETFOCUS IN ASP.NET with C#?

  • 8 months ago

    currently i m using ASP.NET with C# (.net 2003,1.1 framework).
    when i click on a textbox, the default TEXT is to be get cleared.... how to achieve it? - KARAN

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 8 months ago

    you don't want to use javascript ?

    serval

  • 8 months ago

    its ok.. no problem....... but the thing is i need it as a search box.. (i.e... the text box content should be of "Enter the search criteria here..." and this should be italic style. when user click the textbox the content should get clear and normal texts should be typed (i seen this in many sites including MICROSOFT))

  • 8 months ago

    can you check this little code please ?

     

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head>

    <title>Untitled Page</title>

    <style type="text/css">

    #Text1 {

    width: 290px;

    font-style: italic;

    }

    </style>

    <script type="text/javascript">

    function textClearAndNormal()

    {

    document.getElementById(
    "Text1").value="";document.getElementById("Text1").style.fontStyle= "normal";

    }

     

    </script>

    </head>

    <body>

     

    <form id="frm" name = "frm" action = "">

    <input id="Text1" type="text" value = "i am cool" onclick="textClearAndNormal()"/>

    </form>

    </body>

    </html>

  • 8 months ago

    THANKS YAAR! can u help for this ? "

    currently i m using ASP.NET with C# (.net 2005, 2.0 framework)

    i have placed a calendar in my webform (calendar from toolbox --> calendar)

    when i press the ESC key, the calendar should get INVISIBLE... how to do this?

    help me. - KARAN

    "

  • 8 months ago

    hi again ...

    try this

     

    <html>

    <head>

    <title></title>

    </head>

    <body onkeypress = "show_key(event.which)">

    <form runat ="server">

    <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>

    </form>

    <script type="text/javascript">function show_key ( the_key )

    {

    if ( ! the_key )

    {

    the_key = event.keyCode;

    }

    // esc key is number 27  

    if(the_key == 27) {document.getElementById("Calendar1").style.visibility="hidden";

    }

    }

    </script>

    </body>

    </html>

  • 8 months ago

    THANKS A LOT MY DEAR!.. i m searching this for long time.. since i thought that we cant handle the SERVER SIDE process (.net calendar) in client side scripting (javascript).. i m not strong in JAVASCRIPT Sad

    And let me know how to HIDE/DISABLE the close button of Internet explorer using ASP.NET with C#?

  • 8 months ago

    Hi,

        Your code helps me a lot. But i have one contraint while trying the same with multiple option, that is if i try to disable more than one calendar while press ESC, its getting object required error.  

     Thanks in advance,,,,

     

      

  • 8 months ago

    hi,

     if you have more than one calendar , like calerdar1, calendar2, calendar3, and you want to make them all hidden on one action on esc key, you must write modify the previous code like this :

     

    if(the_key == 27) {

    document.getElementById("Calendar1").style.visibility="hidden";

    document.getElementById("Calendar2").style.visibility="hidden";

    document.getElementById("Calendar3").style.visibility="hidden";

    bye

  • 8 months ago

    thanks  friend.but the thing is user may select anyone of the calendar. when user press ESC key, the problem arise... (all the 3 calendar will wont be visible all times. anyone only. User may select any calendar by clicking a button, select value and press ESC key).

  • 8 months ago

    hi this is murthy, why don't you go for AJAX WaterMarkExtender,it is so simple ,when ever u click on text box it shows you a white space or else it shows you a water ever text you had given

  • 8 months ago

    hi karan.

    if the other calendars are "hidden" ; they can't be more hidden when you press esc, so if you leave my last code, i think it will work .

     

    maheshkrp : at work , my boss don't like ajax embeddings for our applications .. because they are made for thousands and thousands users ...  
    So for internal apps, we can use ajax or other stuff, for external apps, only classicak use of client javascript allowed.

  • 8 months ago

    thanks murthy, but i dt know to use AJAX. and i am more interested to implement in my project. can i know where i can find the ajax tutorials (FOR BEGINEERS?)

  • 8 months ago

    thanks serval, i got the exact code.... just refer...

    <script language="javascript" type="text/javascript">
       function show_key ( the_key )
        {
        if ( ! the_key )
         {
          the_key = event.keyCode;
         }
        if(the_key == 27)
         {      
             if(document.getElementById("Calendar1"))
          document.getElementById("Calendar1").style.visibility="hidden";
             if(document.getElementById("Calendar2"))
          document.getElementById("Calendar2").style.visibility="hidden";
          if(document.getElementById("Calendar3"))
          document.getElementById("Calendar3").style.visibility="hidden";
          if(document.getElementById("Calendar4"))
          document.getElementById("Calendar4").style.visibility="hidden";
          if(document.getElementById("Calendar5"))

    }
        }
      </script>

    <body onkeypress="show_key(event.which)">

     

  • 8 months ago

     can anyone help me to my post "CSS OVERLAPPING MENU?? (URGENT!) " ? plz refer and reply

Post a reply

Enter your message below

Sign in or Join us (it's free).