Saturday, March 24, 2012

Set focus on null fields!

Hi,
I have a login form and I have two text boxes in it and the user is required to enter data in the textboxes.If they fail to enter data in any one of the text box and hit the submit button I would like for the cursor to setfocus on the empty text box for the user to enter the data.How would I do this in asp.net.If not would I be able to write Javascript and call the function and where would I call the function.COuld someone expalin how to accomplish this.I do know how to set focus on the first textbox when the page loads up.But I am lost when I am required to setfocus the cursor at the empty text box for user entry?try this:


string strScript = null;
strScript = "<script language=javascript> document.all('TextBox1').focus() </script>";
RegisterStartupScript("focus",strScript);

HI Azam,
I am getting a synatax error. Do I have to declare strScript in my Dim?Also is this a subroutine all by itself or is it part of another subroutine(like page_load)?
Hi,

try to put this code on the Server Side Button Click event.
HI Azam,
I tried your way but I get the error message that says strString is not declared.Also in your code the "TextBox1" would be the ID for the text boxes I have in my project Right?
declare strString as a string variable.

like this:


string strString = "whatever"; // C# syntax

Yes "TextBox1" is the id for the textboxes you have in yr project.
HI Azam,
I am doing this in VB .would the codes be any different if it is VB.
Only syntax.

Here is aC# to VB.NET converter.
HI Azam,
If I did it by your codes would I be able to set focus on the null fields or just the first text box.I am so many error message and that's why I could not see the results.Could you please mail me regarding this?Thanks.
Hi Picky,
Thanks.That is a cool tool!

0 comments:

Post a Comment