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