views:

493

answers:

1

how do i put the onblur and onfocus attributes on a textbox created programatically? here's my code -

td = New HtmlTableCell td.Style.Add("padding-bottom", "5px") Dim txtbox As New TextBox txtbox.Style.Add("width", "96%") txtbox.ID = "ename" td.Controls.Add(txtbox) tr.Cells.Add(td) td.Style.Add("padding-top", "5px")

now i want to add onblur and onfocus. is there something like? --

            txtbox.attributes.Add("onblur","Enter Name")
            txtbox.attributes.Add("onfocus","")

i tried this, and doesn work. does anyone know how to do this?

A: 

onblur and onfocus are JavaScript event handlers. Their values must be valid JavaScript. You're probably looking for something like this:

txtbox.attributes.Add("onblur","this.value = 'Enter Name';")
txtbox.attributes.Add("onfocus","this.value = '';")
BenV