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. onfocus postback problem

onfocus postback problem

Scheduled Pinned Locked Moved ASP.NET
csharpcssasp-netvisual-studio
4 Posts 2 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.
  • M Offline
    M Offline
    minckle
    wrote on last edited by
    #1

    Im using vs 2008 ( asp.net / vb.net ) I've got grid with editable textboxes on the rows ( 1 textbox per column ). On focus of a textbox I need to have a postback to retrieve a related value and display it on screen but after the postback it loses the focus. Is there anything i can do to keep the focus?? tried multiple things online but nothing working yet if i manual set the focus back to the control, then it will just fire the onfocus event - and therefore enter a loop. anyone got any ideas

    N 1 Reply Last reply
    0
    • M minckle

      Im using vs 2008 ( asp.net / vb.net ) I've got grid with editable textboxes on the rows ( 1 textbox per column ). On focus of a textbox I need to have a postback to retrieve a related value and display it on screen but after the postback it loses the focus. Is there anything i can do to keep the focus?? tried multiple things online but nothing working yet if i manual set the focus back to the control, then it will just fire the onfocus event - and therefore enter a loop. anyone got any ideas

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      In this case I would definitely use AJAX rather than postbacks. It will solve you control focus issue and give a better user experience.


      I know the language. I've read a book. - _Madmatt

      M 1 Reply Last reply
      0
      • N Not Active

        In this case I would definitely use AJAX rather than postbacks. It will solve you control focus issue and give a better user experience.


        I know the language. I've read a book. - _Madmatt

        M Offline
        M Offline
        minckle
        wrote on last edited by
        #3

        thanks, but even using ajax it still creates a postback doesnt it. on focus of the control i need it to run some vb.net code ( server side code ). I have ajax set up and it still loads the page_load event so i presume it is still posting back, no ? eiher way i dont have it working with ajax, maybe i have set some thing wrong my code is in pageload event TextBox1Test.Attributes.Add("onfocus", "javascript:DoPostBack('TextBox1Test');") Dim eventTarget As String = Request.Form("__EVENTTARGET") If eventTarget IsNot Nothing Then DayPostback(eventTarget) // server side code i need to run on focus End If javascript code function DoPostBack(control) { __doPostBack(control, "onFocus"); } if i set the DayPostback method to manually set the focus, i get in a loop, if I loop the textbox loses focus after the event has been fired

        modified on Monday, August 1, 2011 7:36 PM

        N 1 Reply Last reply
        0
        • M minckle

          thanks, but even using ajax it still creates a postback doesnt it. on focus of the control i need it to run some vb.net code ( server side code ). I have ajax set up and it still loads the page_load event so i presume it is still posting back, no ? eiher way i dont have it working with ajax, maybe i have set some thing wrong my code is in pageload event TextBox1Test.Attributes.Add("onfocus", "javascript:DoPostBack('TextBox1Test');") Dim eventTarget As String = Request.Form("__EVENTTARGET") If eventTarget IsNot Nothing Then DayPostback(eventTarget) // server side code i need to run on focus End If javascript code function DoPostBack(control) { __doPostBack(control, "onFocus"); } if i set the DayPostback method to manually set the focus, i get in a loop, if I loop the textbox loses focus after the event has been fired

          modified on Monday, August 1, 2011 7:36 PM

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          You are not using AJAX, even in the slightest, most liberal definiation. AJAX is an out of band call, there is no postback involved. You should spend some time reading up on AJAX and its usage if you want to be doing web development.

          function AjaxCall()
          {
          $.ajax({
          type: "POST",
          url: "foo.aspx/Bar",
          data: "text=" + $("[id$='myText']").text(),
          success: onSuccess
          });
          }

          function onSuccess(data)
          {
          $("#myResults).text(data);
          }

          [WebMethod()]
          public static string Bar(string text)
          {
          // DO something
          return "something";
          }

          ALso make note of code snippets are properly formatted. Now you try.


          I know the language. I've read a book. - _Madmatt

          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