Gridview Row textbox.Attributes.Add("onblur",

Posted on 2007-10-15
Medium Priority
Last Modified: 2012-08-13
Given the below code in an gridview RowCreated event:
        if (e.Row.RowType == DataControlRowType.DataRow)
            TextBox textbox =

How can "alert('OnBlur!' above be replaced by javascript focus() of  (TextBox)e.Row.Cells[4].FindControl("txtBox2")? How can txtBox2 be invoked in javascript?
Question by:ksfok
  • 3
LVL 16

Expert Comment

ID: 20082748
I guess you're trying to focus the next row onblur

If textbox's id are ordered as txtBox1, txtBox2, .. , txtBoxN

textbox.Attributes.Add("onblur", "document.getElementById('txtBox'+this.id.substring(6)+1).focus()");
LVL 16

Expert Comment

ID: 20082772
More clean code (group by parentheses)

textbox.Attributes.Add("onblur", "document.getElementById('txtBox'+(this.id.substring(6)+1)).focus()");

Author Comment

ID: 20083069
Please remember here we are not dealing with a plain web page. Our commotion is taking place in a row of textboxes in a gridview's Row Created event. Please help. Thanks.
LVL 16

Accepted Solution

gnoon earned 2000 total points
ID: 20083245
Yes, we're not dealing with a plain web page, but we're providing a plain web page with javascript embed with all textboxes in a table (GridView). Use my code at your original posted code.

The script is not fired at server, but at client after a textbox's focus was leaved.
Or .. It might be I dont understand your question.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

831 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