Click here to Skip to main content
15,920,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Code:
C#
else if (answer is HandwrittenAnswer)
{
  this.Sourcecode.AppendLine("\t\t\t\t<textarea id='" + id + "' name='" + id + "' value='' style='position: absolute; "
                                                         + "top: " + top + "px; left: " + left + "px; height: " + height + "px; width: " + width + "px; "
                                                         + "visibility: hidden; z-index: 2; resize: none;'></textarea>");
  this.Sourcecode.AppendLine("\t\t\t\tdocument.getElementById (" + id + ").focus();");
  
}


with above code when i click on my web form it creates a Control. When i click firsttly it creates a control(a box) where i can write handwritten, but to write something in this control i need to click again because there is no focus ,first line of my code create a control now i want to set a focus so that when i click in it i can write something directly how to do it, for that i tried second line
this.Sourcecode.AppendLine("\t\t\t\tdocument.getElementById (" + id + ").focus();");
but it seems not working instead whole line is written on the Top of my webform..
??? Anybody got a solution???
Posted
Updated 4-Mar-15 0:21am
v2
Comments
Sinisa Hajnal 4-Mar-15 6:27am    
Why are you appending html as string? Why not simply add the control to controls collection and set focus to it?
Member 11000455 4-Mar-15 6:32am    
well this is not my personal project i am working for it so i have to work accordingly. I am developing it and instead of changing whole code i have to solve it in a way it is.

1 solution

Try this. I have placed the statement with in the script tag.

C#
this.Sourcecode.AppendLine("<script>\t\t\t\tdocument.getElementById (" + id + ").focus();</script>");>
 
Share this answer
 
Comments
Member 11000455 4-Mar-15 7:52am    
not working there is no focus set to my control

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900