Set Focus on a TextBox

ASP.NET

    Sponsored Links

    Next

  • 1. 'not found'
    Being new to mobile developing, I was pleased at the ease of development with asp.net using the mobile controls. First app worked like a charm, until someone with a Samsung E715 tried it. You get a very generic "Not Found" error. What should I be doing in the event of an unknown device? Is there a default type of page that is rendered (wml,xhtml)? further notes: the samsung phone uses WAP 2.0; this phone was also not recognized by Request.Browser["IsMobileDevice"]; the page I am trying to load is a reentry page that loads correctly the first pass, but on the second pass when query string variables would be present, is when it errors; there is no authentication being used.

Set Focus on a TextBox

Postby Tmljb2xhcyBIYWVuZW4 » Sat, 03 Apr 2004 22:46:03 GMT

Hello,

I'm developping a Barcode Scanning program on ppc. I need to set focus on a textbox at page load (and so scan directly... with no use of the mouse to go in the textbox before).

I tried this but don't works :

public void setFocus(System.Web.UI.MobileControls.MobileControl champ

	string s
	s = "<script language= \"javascript\">document.getElementById('" +
		champ.ClientID + "').focus()</script>";
	Page.RegisterClientScriptBlock("Focus", s)


private void Page_Load(object sender, System.EventArgs e

	if(Page.IsPostBack==false
	
		this.setFocus(Field_Interet)
	


Thanks a lot for help, Nicolas

RE: Set Focus on a TextBox

Postby jamesche » Sun, 04 Apr 2004 06:06:10 GMT

Hi Nicolas, 

RegisterClientScriptBlock will place your script before the <form> tag on 
the page.  Therefore, when this script is encountered, the TextBox to which 
you are trying to set focus has not yet been rendered.  What you want to do 
is use RegisterStartupScript instead.  That will place your script after 
the closing </form> tag and will work correctly.

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
 XXXX@XXXXX.COM 

This post is provided "AS-IS" with no warranties and confers no rights.


--------------------
< XXXX@XXXXX.COM >
microsoft.public.dotnet.framework.aspnet.mobile:6977

I'm developping a Barcode Scanning program on ppc. I need to set focus on a 
textbox at page load (and so scan directly... with no use of the mouse to 
go in the textbox before). 


I tried this but don't works : 

public void setFocus(System.Web.UI.MobileControls.MobileControl champ)
{
	string s;
	s = "<script language= \"javascript\">document.getElementById('" + 
		champ.ClientID + "').focus()</script>"; 
	Page.RegisterClientScriptBlock("Focus", s);
}

private void Page_Load(object sender, System.EventArgs e)
{
	if(Page.IsPostBack==false)
	{
		this.setFocus(Field_Interet);
	}
}

Thanks a lot for help, Nicolas


RE: Set Focus on a TextBox

Postby Tmljb2xhcyBIQUVORU4 » Wed, 07 Apr 2004 18:31:02 GMT

Hi,

This code don't work 
public void setFocus(MobileControl champ

	string s
	s =
	"<script language=javascript> "
	"   document.getElementById('" +	champ.ClientID + "').focus(); "
	"</script>"

	Page.RegisterStartupScript("Focus", s)


Do you know another way to resolve my problem ?

Thanks, Nicolas 

RE: Set Focus on a TextBox

Postby jamesche » Thu, 08 Apr 2004 23:59:40 GMT

Nicolas, 

Your string contains a newline character as far as C# is concerned.  That 
may be why it's not working for you.  I suspect that this would generate a 
compile error.  You should also use a StringBuilder for this instead of a 
string.  

Here's a code sample to show you what I mean:

<%@ Page Language="C#" %>
<script runat="server">

    void Page_Load(object sender, EventArgs e) {
        System.Text.StringBuilder sb = new System.Text.StringBuilder("");
    
        sb.Append("<script language='JavaScript'>");
        sb.Append("document.getElementById('" + TextBox1.ClientID + 
"').focus();<");
        sb.Append("/");
        sb.Append("script>");
    
        if (!IsStartupScriptRegistered("Focus"))
        {
            this.RegisterStartupScript("Focus", sb.ToString());
        }
    }

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
    </form>
</body>
</html>


Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
 XXXX@XXXXX.COM 

This post is provided "AS-IS" with no warranties and confers no rights.

--------------------
< XXXX@XXXXX.COM >
< XXXX@XXXXX.COM >
microsoft.public.dotnet.framework.aspnet.mobile:6987

This code don't work :
public void setFocus(MobileControl champ)
{
	string s;
	s = 
	"<script language=javascript> "+
	"   document.getElementById('" +	champ.ClientID + "').focus(); "+
	"</script>";

	Page.RegisterStartupScript("Focus", s);
}


Do you know another way to resolve my problem ? 

Thanks, Nicolas 


RE: Set Focus on a TextBox

Postby DotNetJunkies User » Sat, 26 Jun 2004 08:05:53 GMT

The example you are showing here works fine on a PC,
 but not on a PocketPC -  iPaq 5550 Windiws 2003

Marcel

---
Posted using Wimdows.net NntpNews Component -

Post Made from  http://www.**--****.com/ , Ratings, and Searching.

Similar Threads:

1.Set focus on a TextBox

How can I set focus on a TextBox from within a button's 
event handler. 

2.how to set focus on a textbox after onclick of a button

Hi,
I want to set focus on a textbox after i click on a button 
on .aspx page.
I have written it in java script but it sets before 
page_load event occurs and after event of buttonclick it 
goes off!!

can anyone suggest how to set it!1

thanks
sumit

3.Set focus to a textbox on page load

I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
loads, I need the focus to be on one of the textboxes called
txtUserName.

I come from a VB background, so expecting the obvious, I go to the
Page_Load event of the index.aspx page and try to write
txtUserName.SetFocus but I see there isn't a SetFocus method for the
System.Web.UI.WebControls.TextBox class.

What's the way to set the focus to a textbox on the page load in
ASP.NET?

4.Set Focus to a TextBox

How do you set focus to a particular TextBox in ASP.NET?

Thank you in advance. 


5.Newbie question about set focus to a textbox field

6. Setting focus to a textbox

7. Set focus on the textbox field in datagrid

8. Installed CF SP2, Set Focus to first TextBox Control but still can't tab between Controls



Return to ASP.NET

 

Who is online

Users browsing this forum: No registered users and 9 guest