i am trying to associate "onfocusin" of a textbox ( txt_day ) to a function ( javascript code ) .
the code works fine if the text box is used directly on a page.
but if textbox is used in a template column of gridview , javascript error is generated.
reason for that is the html id of control returned by txt_day.clientid is not same as main tag itself.
main tage generated is :
ctl00_ContentPlaceHolder1_DocAttributeValues_GvDocAttributes_ctl04_DC_AttributeValue_txt_day
id returned by txt_day.clientid is :
ctl00_ContentPlaceHolder1_DocAttributeValues_GvDocAttributes_ctl02_DC_AttributeValue_txt_day
below is the complete code :
Code:txt_day.Attributes.Add("onfocusin", "gotfocus()") Dim StrScript As String StrScript = "<script language=javascript>" StrScript = StrScript & "function gotfocus()" StrScript = StrScript & "{" StrScript = StrScript & "if (document.getElementById('" & txt_day.ClientID & "').value=='day')" StrScript = StrScript & "{" StrScript = StrScript & "document.getElementById('" & txt_day.ClientID & "').value='';" StrScript = StrScript & "}" StrScript = StrScript & "}" StrScript = StrScript & "</script>" Page.RegisterStartupScript("gotfocus", StrScript)




Reply With Quote