Solved

Add javascript event handler to a web control - in 1.1.

Posted on 2006-10-23
3
244 Views
Last Modified: 2008-03-10
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.IsClientScriptIncludeRegistered(typ, js))
  Page.ClientScript.RegisterClientScriptInclude(typ, js, js);
  ddlTest.Attributes.Add("onKeyDown", "TADD_OnKeyDown(this);");
}

thx
--steve...
0
Comment
Question by:juststeve
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
Roopesh_7 earned 350 total points
ID: 17792807
yes we can achive thi also in 1.1 its nothing but only binding that web control with javascript
0
 

Author Comment

by:juststeve
ID: 17794453
Thankx...I've been able to get basic functionality working by using:

        Dim scriptString As String
        scriptString = "<script language=JavaScript>"
        scriptString = scriptString & "TADD_OnKeyDown(this);"
        scriptString = scriptString & "</script>"

        If (Not IsStartupScriptRegistered("ddFindUser")) Then
            RegisterStartupScript("ddFindUser", scriptString.ToString)
        End If

        ddFindUser.Attributes.Add("onKeyDown", "TADD_OnKeyDown(this);")

Where I'm populating a dropdown thusly:
        ddFindUser.DataSource = ds.Tables(0).DefaultView
        ddFindUser.DataTextField = "strUName"
        ddFindUser.DataValueField = "UserIdentity"
        ddFindUser.Items.Insert(0, "All")
        ddFindUser.DataBind()

That produces this line in the rendered control:
<select name="ddFindUser" id="ddFindUser" onKeyDown="TADD_OnKeyDown(this);">
(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.


0
 

Author Comment

by:juststeve
ID: 17794776
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now