Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to get onfocus OR onenter Textbox asp.net

how to get onfocus OR onenter Textbox asp.net

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nettutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jojoba2011
    wrote on last edited by
    #1

    Hi, i wanna to call the bellow function while the Textbox1 got focus (when user click on Textbox1 OR when user press tab and textbox1 got focus):

    `Untitled Page            function Open() {             var Return;             var myObject = new Object();             myObject.TextBox1 = document.getElementById("txtFirstName").value;             if (window.showModalDialog) {                 Return = window.showModalDialog("childform.aspx", myObject, "dialogWidth:670px;dialogHeight:600px;")                 document.getElementById("txtFirstName").value = Return.firstname;                 }         }`
    
    S M 2 Replies Last reply
    0
    • J jojoba2011

      Hi, i wanna to call the bellow function while the Textbox1 got focus (when user click on Textbox1 OR when user press tab and textbox1 got focus):

      `Untitled Page            function Open() {             var Return;             var myObject = new Object();             myObject.TextBox1 = document.getElementById("txtFirstName").value;             if (window.showModalDialog) {                 Return = window.showModalDialog("childform.aspx", myObject, "dialogWidth:670px;dialogHeight:600px;")                 document.getElementById("txtFirstName").value = Return.firstname;                 }         }`
      
      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      Write this in your code behind file:

      myTextBox.Attributes.Add("onfocus","javascript: Open();");

      This will add the onfocus client side event to your textbox.

      Sandeep Mewara Microsoft ASP.NET MVP [My latest Article]: Server side Delimiters in ASP.NET[^]

      1 Reply Last reply
      0
      • J jojoba2011

        Hi, i wanna to call the bellow function while the Textbox1 got focus (when user click on Textbox1 OR when user press tab and textbox1 got focus):

        `Untitled Page            function Open() {             var Return;             var myObject = new Object();             myObject.TextBox1 = document.getElementById("txtFirstName").value;             if (window.showModalDialog) {                 Return = window.showModalDialog("childform.aspx", myObject, "dialogWidth:670px;dialogHeight:600px;")                 document.getElementById("txtFirstName").value = Return.firstname;                 }         }`
        
        M Offline
        M Offline
        Mayank_Gupta_
        wrote on last edited by
        #3

        In order to call the JavaScript function, Just use the Following: protected void Page_Load(object sender, EventArgs e) { TextBox1.Attributes.Add("onfocus", "Open()"); } This will bind the "onfocus" event of TextBox1 to the javascript function "Open()"

        A 1 Reply Last reply
        0
        • M Mayank_Gupta_

          In order to call the JavaScript function, Just use the Following: protected void Page_Load(object sender, EventArgs e) { TextBox1.Attributes.Add("onfocus", "Open()"); } This will bind the "onfocus" event of TextBox1 to the javascript function "Open()"

          A Offline
          A Offline
          Amir Jalilifard
          wrote on last edited by
          #4

          But unlike others i believe you should handle it from your client and not ASP.net. You should implement it as follow:

          document.getElementById("<%= TextBox1.ClientID %>").onfocus=function(){Open();}

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups