Link to home
Start Free TrialLog in
Avatar of ksfok
ksfok

asked on

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.
Avatar of gnoon
gnoon
Flag of Thailand image

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()");
More clean code (group by parentheses)

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

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of gnoon
gnoon
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial