• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5495
  • Last Modified:

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

Given the below code in an gridview RowCreated event:
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TextBox textbox =
            (TextBox)e.Row.Cells[3].FindControl("txtPatient");
            textbox.Attributes.Add("onblur",
            "alert('OnBlur!');");    
        }

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?
Thanks.
0
ksfok
Asked:
ksfok
  • 3
1 Solution
 
gnoonCommented:
I guess you're trying to focus the next row onblur

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

textbox.Attributes.Add("onblur", "document.getElementById('txtBox'+this.id.substring(6)+1).focus()");
0
 
gnoonCommented:
More clean code (group by parentheses)

textbox.Attributes.Add("onblur", "document.getElementById('txtBox'+(this.id.substring(6)+1)).focus()");
0
 
ksfokAuthor Commented:
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.
0
 
gnoonCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now