juststeve
asked on
Add javascript event handler to a web control - in 1.1.
I'm attempting to implement a set of javascript functions that produce type ahead functionality for a .net dropdown list box as found at:
http://aspalliance.com/articleViewer.aspx?aId=775&pId=-1
Alas, that solution assumes .net 2.0 where the code-behind rests on using the block below. I _think this is doing nothing more complicated than assigning a javascript function to an event on the rendered web control...can that be achieved in the 1.1 framework?
{
Type typ = GetType();
if (!Page.ClientScript.IsClie ntScriptIn cludeRegis tered(typ, js))
Page.ClientScript.Register ClientScri ptInclude( typ, js, js);
ddlTest.Attributes.Add("on KeyDown", "TADD_OnKeyDown(this);");
}
thx
--steve...
http://aspalliance.com/articleViewer.aspx?aId=775&pId=-1
Alas, that solution assumes .net 2.0 where the code-behind rests on using the block below. I _think this is doing nothing more complicated than assigning a javascript function to an event on the rendered web control...can that be achieved in the 1.1 framework?
{
Type typ = GetType();
if (!Page.ClientScript.IsClie
Page.ClientScript.Register
ddlTest.Attributes.Add("on
}
thx
--steve...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it appears that the only thing I need to do is:
ddFindUser.Attributes.Add( "onKeyDown ", "TADD_OnKeyDown(this);")
The RegisterStartupScript block is not needed. It appears that block had been adding an addtional line at the page level causeing the error.
ddFindUser.Attributes.Add(
The RegisterStartupScript block is not needed. It appears that block had been adding an addtional line at the page level causeing the error.
ASKER
Dim scriptString As String
scriptString = "<script language=JavaScript>"
scriptString = scriptString & "TADD_OnKeyDown(this);"
scriptString = scriptString & "</script>"
If (Not IsStartupScriptRegistered(
RegisterStartupScript("ddF
End If
ddFindUser.Attributes.Add(
Where I'm populating a dropdown thusly:
ddFindUser.DataSource = ds.Tables(0).DefaultView
ddFindUser.DataTextField = "strUName"
ddFindUser.DataValueField = "UserIdentity"
ddFindUser.Items.Insert(0,
ddFindUser.DataBind()
That produces this line in the rendered control:
<select name="ddFindUser" id="ddFindUser" onKeyDown="TADD_OnKeyDown(
(Since I don't have any 2.0 projects setup i can't run a test against the original code to see how _it renders the HTML control, but this certainly _looks like it should look....
And the type ahead functionality _does, in fact, work. However...after IE has loaded the page it reports a javascript error occurred at this point in one of the js functions that, to all outward appearances, is working correctly:
function TADD_OnKeyDown(tb)
{
if (event.ctrlKey) //this line reports error: 'Object required'
return;
NOTE: the error is reported via the status bar page load indicator...not a popup dialog explicitly presented to the user.