PreRender code seems to cause Javascript error!

Discussion in 'ASP .Net' started by Edward, Feb 3, 2005.

  1. Edward

    Edward Guest

    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
    --
    The reading group's reading group:
    http://www.bookgroup.org.uk
     
    Edward, Feb 3, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?Q?Ti=EBsto?=

    Creating ClientSide code thru PreRender

    =?iso-8859-1?Q?Ti=EBsto?=, Nov 11, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    473
    Steven Cheng[MSFT]
    Nov 13, 2004
  2. Ian Cox
    Replies:
    4
    Views:
    2,425
    Steven Cheng[MSFT]
    Dec 15, 2004
  3. Jéjé
    Replies:
    1
    Views:
    3,690
    3cMaverick
    May 12, 2006
  4. news.microsoft.com

    Hidden Validators Cause Javascript Error

    news.microsoft.com, Apr 5, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    401
    news.microsoft.com
    Apr 5, 2006
  5. Iver Erling Årva
    Replies:
    2
    Views:
    93
    Iver Erling Årva
    Aug 19, 2004
Loading...

Share This Page