AJAX and registering JavaScript code

tfowler

Regular
Joined
Aug 16, 2005
Messages
84
Location
Columbus, OH
Ok, I have searched the web forever for this and found suggestions, but none of them seem to work for my stituation. So, here I am. I am using AJAX.NET 1.0. I have a page with two UpdatePanels. The first contains a DropDownList and three Panels which contain various controls. When the user selects an item from the DropDownList, the appropriate Panel is displayed, while the others are hidden. This works great. The second UpdatePanel control contains a GridView. Right-clicking and dragging on the GridView paints the cells different colors (using a JavaScript routine) depending on the selection in the DropDownList. This works great when the page first loads, but stops working after a different item is selected from the DropDownList.

I have read a variety of threads about using ScriptManager.RegisterClientScriptBlock to register my JavaScript code. I have tried to do this in Page_PreRender, Page_Load, UpdatePanel1_PreRender, UpdatePanel1_Load, UpdatePanel2_PreRender, UpdatePanel2_Load, and all of the combinations at once...but I can't get it to work! I'm at a complete loss.

My JavaScript looks something like:
Code:
[SIZE=2]<script language="javascript" type="text/javascript">[/SIZE]
[SIZE=2]/* script for changing the background color of the table cells based on the "Selection Mode" */[/SIZE]
[SIZE=2]document.getElementById('<%GridView1.ClientID %>').onmousemove = MouseMove;[/SIZE]
[SIZE=2]document.getElementById('<%GridView1.ClientID %>').onmousedown = MouseMove;[/SIZE]
[SIZE=2]document.getElementById('<%GridView1.ClientID %>').oncontextmenu = DontShowContext;[/SIZE]
[SIZE=2]document.getElementById('<%GridView1.ClientID %>').onmouseup = MouseUp;[/SIZE]
 
[SIZE=2]// handle the MouseMove event for the GridView control[/SIZE]
[SIZE=2]function MouseMove(event)[/SIZE]
 
 
 

[SIZE=2]{[/SIZE][INDENT][SIZE=2]:[/SIZE][/INDENT][INDENT][SIZE=2]:[/SIZE][/INDENT][INDENT][SIZE=2]WITH THE CODE TO CHANGE COLORS HERE[/SIZE][/INDENT][SIZE=2][[/SIZE]/code]
 
So, registering all of the JavaScript using [B]ScriptManager.RegisterClientScriptBlock[/B] doesn't work because I get errors about the GridView object not existing (since it hasn't been rendered yet). So, I split the non-funtion code out and try to register it using [B]ScriptManager.RegisterStartupScript[/B]. I no longer get the script errors, but I am back to the original problem!
 
Thanks for any help you can provide,
Todd [IMG]http://forums.asp.net/emoticons/emotion-7.gif[/IMG]
 
Back
Top