Error using RegisterClientScriptBlock

Discussion in 'ASP .Net' started by Steven K, Apr 14, 2004.

  1. Steven K

    Steven K Guest

    Hello,

    I am trying to create a JavaScript function and am getting the following
    error: 'jsFormValidation' is not a member of 'ASP.ciJava_aspx'.

    Sub Page_Load(Sender As Object, E As EventArgs)
    Dim ctrlValidate As String = tbxSubmitter.ID
    Dim strFormValidation As String = _
    "<script language='javascript'> function jsFormValidation() {" & _
    "alert('Please enter your Name in the |Name| field.');" & _
    "document.getElementById('" & ctrlValidate & "').focus();}" & _
    "<" & "/script>"

    If(Not IsClientScriptBlockRegistered("jsFormValidation"))
    RegisterClientScriptBlock("jsFormValidation", strFormValidation)
    End If
    End Sub


    In the form:

    <td width="100" align="center">
    <asp:ImageButton runat="server"
    ImageURL="../../images/art_dbflash_go.jpg"
    ImageAlign="Middle"
    AlternateText="sckeels"
    OnCommand="jsFormValidation(this)"
    CommandName="ASPNET"/>
    </td>
     
    Steven K, Apr 14, 2004
    #1
    1. Advertising

  2. You're trying to use a client-side JavaScript function to handle a
    server-side event.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Steven K" <> wrote in message
    news:...
    > Hello,
    >
    > I am trying to create a JavaScript function and am getting the following
    > error: 'jsFormValidation' is not a member of 'ASP.ciJava_aspx'.
    >
    > Sub Page_Load(Sender As Object, E As EventArgs)
    > Dim ctrlValidate As String = tbxSubmitter.ID
    > Dim strFormValidation As String = _
    > "<script language='javascript'> function jsFormValidation() {" & _
    > "alert('Please enter your Name in the |Name| field.');" & _
    > "document.getElementById('" & ctrlValidate & "').focus();}" & _
    > "<" & "/script>"
    >
    > If(Not IsClientScriptBlockRegistered("jsFormValidation"))
    > RegisterClientScriptBlock("jsFormValidation", strFormValidation)
    > End If
    > End Sub
    >
    >
    > In the form:
    >
    > <td width="100" align="center">
    > <asp:ImageButton runat="server"
    > ImageURL="../../images/art_dbflash_go.jpg"
    > ImageAlign="Middle"
    > AlternateText="sckeels"
    > OnCommand="jsFormValidation(this)"
    > CommandName="ASPNET"/>
    > </td>
    >
    >
     
    Kevin Spencer, Apr 14, 2004
    #2
    1. Advertising

  3. Hi Steven

    The reason is that OnCommand is a server-side event. How can you call a client-side javascript function through server-side
    Please try add this line
    Imagebutton1.Attributes("onclick") = "jsFormValidation();
    and remove this line
    OnCommand="jsFormValidation(this)

    Bin Song, MC



    Sub Page_Load(Sender As Object, E As EventArgs
    Dim ctrlValidate As String = tbxSubmitter.I
    Dim strFormValidation As String =
    "<script language='javascript'> function jsFormValidation() {" &
    "alert('Please enter your Name in the |Name| field.');" &
    "document.getElementById('" & ctrlValidate & "').focus();}" &
    "<" & "/script>

    If(Not IsClientScriptBlockRegistered("jsFormValidation")
    RegisterClientScriptBlock("jsFormValidation", strFormValidation
    End I
    Imagebutton1.Attributes("onclick") = "jsFormValidation();
    End Su


    In the form

    <td width="100" align="center"><asp:ImageButton runat="server
    ImageURL="../../images/art_dbflash_go.jpg
    ImageAlign="Middle
    AlternateText="sckeels
    CommandName="ASPNET"/></td>
     
    =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=, Apr 14, 2004
    #3
    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. Mark
    Replies:
    1
    Views:
    1,585
  2. MW
    Replies:
    3
    Views:
    479
  3. Steve Powell
    Replies:
    3
    Views:
    3,084
    Steve Powell
    Jun 21, 2005
  4. kewl
    Replies:
    2
    Views:
    2,195
    Bruce Barker
    Mar 14, 2006
  5. registerclientscriptblock error

    , Apr 27, 2005, in forum: ASP .Net Building Controls
    Replies:
    5
    Views:
    139
Loading...

Share This Page