Click here to Skip to main content
16,012,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,
In my site, Login window open as POPUP using AJAX call.
Please refer below screen grab:
$('#hrefLogin').click(function () {
var url = $('#divLogin').data('request-path');

$.ajax({
url: url,
type: 'GET',
success: function (data) {
////Render the partial view HTML returned by the action method
$("#divLogin").html(data);

$.fancybox({
href: "#divLogin",
'maxWidth': 420, // set the width
'minHeight': 400,
'maxHeight': 400,
'height':'auto',
'autoSize': false
});

$.fancybox.update();

////Reparse html data to enable MVC data annotation work.
$('form').removeData('validator');
$('form').removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse('form');
}
});
});

Login window have two input fields UserName and Password.
I need to set focus on UserName field when popup open.

Many Thanks,

Regards,
Lalitha
Posted

1 solution

You can use the following code to set the focus:



ScriptManager sm = ScriptManager.GetCurrent(this);
sm.SetFocus(myTextBox);


In case of modal popup


function modalSetup()


{


var modalPopup = $find('"ModalPopupExtender1.ClientID"');


modalPopup.add_shown(myTextBox);


}


To set focus and select text of a you have to use the following:


ScriptManager.RegisterStartupScript(this, this.GetType(), "selectAndFocus", "$get('" + myTextBox.ClientID + "').focus();$get('" + myTextBox.ClientID + "').select();", true);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900