Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
I am developing a Simple Web Application in ASP.NET.
My First TextBox is set as ReadOnly.
 
So I want to focus on my second TextBox i.e. TextBox2.
 
I tried with the following codes.
protected void Page_Load(object sender, EventArgs e)
    {
        TextBox2.Focus();
    }
 
or
protected void Page_PreRender(object sender, EventArgs e)
    {
        TextBox2.Focus();
       
    }
or
protected void Page_Load(object sender, EventArgs e)
    {
        Page.SetFocus(TextBox2);
    }
 

protected void Page_PreRender(object sender, EventArgs e)
    {
        Page.SetFocus(TextBox2);
       
    }
 
but none of the code is working.
Cursor placed in TextBox2 by those code. but the cursor is not blinking.
So, I can't write in the textbox until I use my mouse to move the pointer and click there in textbox.
I need the cursor to be blink and be able to write at the time of page load.
 
Please suggest!
Posted 27-Jan-13 6:21am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try to use javascript
 window.onload = function () {
            document.getElementById('<%Response.Write(TextBox2.ClientID); %>').focus();
        }
  Permalink  
Comments
Sourav Sarkar-SS2 at 28-Jan-13 14:12pm
   
thank you so much
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
Try this:
protected void Page_Load(object sender, EventArgs e)
    {
       Page.Form.DefaultFocus = TextBox2.ClientID;
    }
  Permalink  
Comments
Sourav Sarkar-SS2 at 27-Jan-13 13:18pm
   
Thanks for your reply.
But sir
Its not working, the same problem mentioned in my question persist.
Please help in any other way.
thanks
ProgramFOX at 27-Jan-13 13:36pm
   
It's working fine for me.
Sourav Sarkar-SS2 at 27-Jan-13 13:53pm
   
no sir
in my case cursor is not blinking.
please help
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This code is working fine on page load and cursor is also blinking
 
TextBox1.Focus();
  Permalink  
Comments
Sourav Sarkar-SS2 at 28-Jan-13 13:54pm
   
That is why I wrote textBox2
and textbox1 should be read-only.
Sourav Sarkar-SS2 at 28-Jan-13 14:13pm
   
Read the question carefully and then try to answer
bye

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



Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 27 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100