?
Solved

Javascript focus applied to a gridview cell textbox

Posted on 2007-10-15
2
Medium Priority
?
2,622 Views
Last Modified: 2010-05-18
Given the below javascript on a plain page:
"<script>document.getElementById('" + TextBox1.ClientID + "').focus();</script>"
how can it be applied in a gridview rowcreated event for TextBox1 in a cell?
Thanks.
0
Comment
Question by:ksfok
2 Comments
 
LVL 26

Accepted Solution

by:
Rejojohny earned 750 total points
ID: 20083101
try in rowcreated event
if e.Row.RowType = DataControlRowType.DataRow then
Dim mytextbox as textbox = ctype(e.Row.Cells(3).FindControl("txtTextBox"), textbox)
page.clientscript.RegisterClientScriptBlock(me.gettype(), "setfocus", "document.getElementById('" + mytextbox.clientid + "').focus();")
end if


Rejo
0
 
LVL 27

Assisted Solution

by:Sammy Ageil
Sammy Ageil earned 750 total points
ID: 20083152
      if (e.Row.RowType == DataControlRowType.DataRow)
{

if (e.Row.RowIndex == 0)
{
   
TextBox tempTextBox = (TextBox)e.Row.FindControl("Textbox1") as TextBox;
 System.Text.StringBuilder sb = new System.Text.StringBuilder(@"window.onload= function()
{document.getElementById('" + tempTextBox.ClientID + "').focus();\n}\t\n");
 Page.ClientScript.RegisterStartupScript(this.GetType(), "CtrlFocus", sb.ToString(),true);

}
}
this will see the focus on the first TextBox on the row
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question