PreRender code seems to cause Javascript error!

E

Edward

I'm strictly a high-level programmer, so please excuse my ignorance of
the inner magic of ASP etc.

I have what my company calls a "builder form". It is used to maintain
static lookup lists. It contains a Datagrid control with an Edit
Template specified.

The code behind contains the following function:

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender

' If in not edit mode activate row highlighting / click to edit
If Not Editing Then
BuilderForm.ActivateRowHighlight(Me.Page)
BuilderForm.ActivateClicktoEdit(Me.Page)
End If

End Sub

This calls the following two functions:

Public Sub ActivateRowHighlight(ByRef page As Page, Optional ByVal
gridName As String = "dgSearch")

' Inject Jscript to activate row highlight and selection
page.RegisterStartupScript(Guid.NewGuid.ToString, "<script
language=javascript>try{HighlightTableRow('" + gridName +
"');}catch(e){}
</script>")

End Sub

Public Sub ActivateClicktoEdit(ByRef page As Page, Optional ByVal
gridName As String = "dgSearch")

' Inject Jscript to attack click event to grid
page.RegisterStartupScript(Guid.NewGuid.ToString, "<script
language=javascript>" + gridName + ".attachEvent('onclick',
DoClick);</script>")

End Sub

"HighlightTableRow" is defined in a .js file which is included in the
..aspx, as is the function "DoClick".

We have about a dozen of these builder forms and they work well. They
display the table rows, the user clicks on the row to edit it, and the
Datagrid flips into edit mode.

However, on the form I am working on, the form fails to load with the
following error:

Microsoft JScript runtime error: 'dgSearch' is undefined

on the line which comes from the second function:

<script language=javascript>dgSearch.attachEvent('onclick', DoClick);

(dgSearch is the company-mandated name for the Datagrid)

What appears to be happening is that in the HTML prior to the line
causing the error, there is no "dgSearch" control loaded. Where I
would expect it to be is completely blank!

<TR>
<TD>
<TABLE id="Table10" cellSpacing="0" cellPadding="0"
width="100%">
<TR>
<TD><IMG src="../../images/mnus32.gif" border="0">
</TD>
<TD width="100%">
<table cellspacing="2" cellpadding="2" id="wmSubMenu"
border="0">
<tr>
SHOULD BE HERE!!!
</tr>
</table>
</TD>
</TR>
</TABLE>
</TD>
</TR> <!-- Grid Results -->

Does anyone have a clue where it might have gone? I think the problem
may be in the order the objects are rendered, but I can't find
anything different about this form than any other which works fine.

Many thanks if you've made it this far!

Edward
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top