Running Javascript and ASP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dukey11
    New Member
    • Oct 2006
    • 2

    Running Javascript and ASP

    I want to run some javascript code and then some ASP.NET code.
    I can do both function seperately by pressing two different objects. But I cannot to then off one object.


    Below I have:

    > An image which when I click runs a javascript function.
    > A button which does the ASP.NET processing.

    I want to run both the javascript and ASP.NET off a single click of the ASP button (btnsub_Click).

    [PHP]
    <%@ Page Language="VB" %>
    <script runat="server">

    Sub btnsub_Click(By Val Sender As Object, ByVal E As EventArgs)

    If Page.IsValid Then
    ' Do Something

    End If
    End Sub
    </script>

    <html>
    <head><script type="text/javascript">
    javafunction() etc.. etc..
    </script>
    </head>

    <a onclick="javafu nction()"><img src="graphic.gi f" /></a>

    <asp:button id="btnsub" text="Submit" onClick="btnsub _Click" runat="server" />
    [/PHP]


    __

    Does anyone know I can add "javafunction() " to the button click code?


    Would appreciate any help.

    Thanks
  • scripto
    New Member
    • Oct 2006
    • 143

    #2
    Yes you can !!!

    <asp:button id="btnsub" text="Submit" onClick="btnsub _Click; javafunction()" runat="server" />

    decide which function you want to run first and put it first.

    Comment

    • dukey11
      New Member
      • Oct 2006
      • 2

      #3
      Hi Scripto,

      Thanks for your help!

      I tried putting both actions (javascript and vb button click ) on the click event of the ASP.NET button - like you said.

      Unfortunately I get this error ::::

      [PHP]Compilation Error
      Description: An error occurred during the compilation of a resource
      required to service this request.

      Please review the following specific error details and modify
      your source code appropriately.

      Compiler Error Message: BC30456: 'myjavafunction ' is not a member of 'myfile.aspx'.


      [/PHP]


      Do you have any further suggestions as to what I am doing wrong

      Thanks

      Comment

      • scripto
        New Member
        • Oct 2006
        • 143

        #4
        My error - i was obviously thinking classic ASP

        here goes:

        in the Page_Load() function, add this line
        Button1.Attribu tes.Add("onclic k", "myjavafunction ()");

        That will execute before the server side button_Click() function
        you can add as many of these lines as you wish, each with a different myjavafunction( )

        sorry about the mixup.

        Comment

        • Petra
          New Member
          • Oct 2006
          • 13

          #5
          Hello!

          I have a question to this topic:

          Is it possible to define the sequense of the functions which i add with:

          Button.Attribut es.Add("onclick ", "MM_goToURL ()")

          Because I like to go run through the ASP Code first.

          Thank you for your help!!
          Petra

          Comment

          • scripto
            New Member
            • Oct 2006
            • 143

            #6
            The way it is coded now the javascript will run first. If you want the ASP or server side code to run first, then take a look at a function called RegisterClientS criptBlock() This is coded in your Button1_Click() event , but it registers the javascript code for you, so that function would be put at the very end of you server side code.

            That will work - i use it all the time.

            Comment

            • Petra
              New Member
              • Oct 2006
              • 13

              #7
              Thanks a lot!!!!!

              It works fine!!!

              Best regards from Vienna!
              Petra

              Originally posted by scripto
              The way it is coded now the javascript will run first. If you want the ASP or server side code to run first, then take a look at a function called RegisterClientS criptBlock() This is coded in your Button1_Click() event , but it registers the javascript code for you, so that function would be put at the very end of you server side code.

              That will work - i use it all the time.

              Comment

              • scripto
                New Member
                • Oct 2006
                • 143

                #8
                here you are:

                Dim scriptString As String = "<script language=JavaSc ript> function MM_goToURL() {"
                scriptString += "alert("TESTlll lllllllllllllll llllllllllllll" );}"
                scriptString += "/"
                scriptString += "script>"

                RegisterClientS criptBlock("sta rt", scriptString)

                End Sub

                remove the javascript function that you have MM_goToURL it is not needed.

                Comment

                Working...