Search This Blog

Tuesday, February 1, 2011

Set focus to textbox after postback

In my web application which is developed using ajax, I had a problem. My textbox lost its focus after a postback, so I supposed to solve this issue with the textbox. Then I came with a solution using javascript. This may be helpful to some one

Put this javascript on your updatepanel page. You may have to change controls id strings.

<script type="text/javascript">
  var postbackElement;
  function beginRequest(sender, args) {
      postbackElement = args.get_postBackElement();
  function pageLoaded(sender, args) 
      var updatedPanels = args.get_panelsUpdated();
      if (typeof(postbackElement) === "undefined"
      else if ('button1') > -1) 
          for (i=0; i < updatedPanels.length; i++) { 
              document.getElementById('<%= TextBox1.ClientID %>').focus();

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.