Community discussion forum

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

  • 1 year 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
  • 1 year ago

    you don't want to use javascript ?

    serval

  • 1 year 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))

  • 1 year 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>

  • 1 year 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

    "

  • 1 year 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>

  • 1 year 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#?

  • 1 year 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,,,,

     

      

  • 1 year 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

  • 1 year 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).

  • 1 year 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
  • 1 year 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.

  • 1 year 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?)

  • 1 year 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)">

     

  • 1 year 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).

We'd love to hear what you think! Submit ideas or give us feedback