Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox focus on button click

Status
Not open for further replies.
Joined
Apr 11, 2002
Messages
193
Location
IN
Hi,

I am using ASP.net 2.0. I want to give focus on a textbox on a click of a button. I have written a javascript function and i am adding it as a attribute to the button.
Javascript :
function GetFocusonElements(element)
{
window.parent.frames('MainFrame').document.getElementById(element).focus();
return false;
}

Code Behind :
btn.Attributes.Add("onClick", "javascript:return GetFocusonElements('txtQty');");

When i click on the button the javascript function gets executed but there is no focus and there is a postback. When i click the second time then there is no postback and the textbox gets the focus.

I cant use focus() of textbox as i am using AJAX.

Can anyone please help me with this issue.

Thank you,
Manish
 
Hi Mark,

I am adding the "btn.Attributes.Add" line in page_load event.

Thanks,
Manish
 
Try adding the javascript code to the OnClientClick event in your aspx page (rather than from the code behind page). Does that make a difference?


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Mark,

It still give the same result. I am confused.

You want to have a look at the entire html content?

Thanks,
Manish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top