Post Back and Javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • voidinutah@gmail.com

    Post Back and Javascript

    Hello,

    I'm new to .NET and was trying to find a solution for having a button
    control do a post back then execute a javascript function.

    When the button is clicked a post back occurs to save the user data,
    after that a javascript function is called to load a new video. If it
    wasn't for the video, then I would have used panel controls to hide/
    show the content. We are using swfobject to load a series of videos on
    the same page, and breaking it out into separate pages is not an
    option unfortunately.

    Thanks for any help.
    Marc
  • Mark Rae [MVP]

    #2
    Re: Post Back and Javascript

    <voidinutah@gma il.comwrote in message
    news:4a5c1511-15de-41d9-b877-15700824bfbe@i2 4g2000prf.googl egroups.com...
    I'm new to .NET and was trying to find a solution for having a button
    control do a post back then execute a javascript function.
    <head>
    <script type="text/javascript">
    function myFunction()
    {
    // code goes here
    }
    </script>
    </head>
    <body>
    <form ID="MyForm" runat="server">
    <asp:Button ID="MyButton" runat="server" Text="Click"
    OnClick="MyButt on_Click" />
    </form>
    </body>

    protected void MyButton_Click( object sender, EventArgs e)
    {
    if (IsPostBack)
    {
    // postback code goes here

    ClientScript.Re gisterStartupSc ript(this.GetTy pe(), "postBack",
    "myFunction();" , true);
    }
    }


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • voidinutah@gmail.com

      #3
      Re: Post Back and Javascript

      On Nov 3, 9:51 am, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
      <voidinu...@gma il.comwrote in message
      >
      news:4a5c1511-15de-41d9-b877-15700824bfbe@i2 4g2000prf.googl egroups.com...
      >
      I'm new to .NET and was trying to find a solution for having a button
      control do a post back then execute a javascript function.
      >
      <head>
          <script type="text/javascript">
              function myFunction()
              {
                  // code goes here
              }
          </script>
      </head>
      <body>
          <form ID="MyForm" runat="server">
              <asp:Button ID="MyButton" runat="server" Text="Click"
      OnClick="MyButt on_Click" />
          </form>
      </body>
      >
      protected void MyButton_Click( object sender, EventArgs e)
      {
          if (IsPostBack)
          {
              // postback code goes here
      >
              ClientScript.Re gisterStartupSc ript(this.GetTy pe(), "postBack",
      "myFunction();" , true);
          }
      >
      }
      >
      --
      Mark Rae
      ASP.NET MVPhttp://www.markrae.net
      Thanks for your help Mark! With the code you provided, I was able to
      test a few things. The issue I was having was that the button was in
      an update panel. Since it was in an update panel, the code wasn't
      working. Once I removed the update panel it worked fine. But the issue
      I have now is that the video starts playing again since the entire
      page is posting back.

      With the multiple videos page, I can add a hidden field to handle
      which video to play.

      But on the page I've been working on, there is only one video. After
      the video plays the continue button is enabled. The user clicks the
      button, the data needs to be saved, then a modal window opens with
      some text. The video in the background needs to stay at the end
      position. But with removing the update panel, and the entire page
      posting back, the video is starting again. Any ideas for this
      scenario?

      Thanks again!
      Marc

      Comment

      • Mark Rae [MVP]

        #4
        Re: Post Back and Javascript

        <voidinutah@gma il.comwrote in message
        news:7fe5af27-fa85-482f-984e-a8aea05a2d9d@u2 9g2000pro.googl egroups.com...
        Any ideas for this scenario?
        Not without seeing your code...


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • voidinutah@gmail.com

          #5
          Re: Post Back and Javascript

          On Nov 3, 12:44 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
          <voidinu...@gma il.comwrote in message
          >
          news:7fe5af27-fa85-482f-984e-a8aea05a2d9d@u2 9g2000pro.googl egroups.com...
          >
          Any ideas for this scenario?
          >
          Not without seeing your code...
          >
          --
          Mark Rae
          ASP.NET MVPhttp://www.markrae.net
          Here is the aspx page. There's a master page that I did not include,
          so if you need a stripped down version of the aspx, let me know.

          ----------------------------------------
          BEGIN of aspx
          ----------------------------------------
          <%@ page language="VB" masterpagefile= "~/dir_user_interf ace/
          dir_master_page/DashboardMaster .master"
          autoeventwireup ="false" codefile="defau lt.aspx.vb"
          inherits="mod_1 0_20_10_070_def ault" %>

          <asp:Content ID="conHead" ContentPlaceHol derID="cphDashb oardHead"
          Runat="Server">

          <script src="../../dir_script/swfobject.js" type="text/
          javascript"></script>
          <script type="text/javascript">

          function video_complete( ) {
          if ($get('<%= btnContinueButt on_1.ClientID %>').className
          == "Visible") {
          btn_Continue = $get('<%= btnContinueButt on_1.ClientID
          %>');
          btn_Continue.di sabled = false;
          }
          }

          function endOfStepModal( ) {
          var theBehavior = $find("EndOfSte pOpenBehavior") ;
          var theAnimation = theBehavior.get _OnClickBehavio r();
          theAnimation.pl ay();
          }

          </script>

          </asp:Content>
          <asp:Content ID="conModal" ContentPlaceHol derID="cphDashb oardModal"
          Runat="Server">
          <asp:panel id="pnlEndOfSte pController" runat="server"
          cssclass="Hidde n">
          </asp:panel>
          <asp:panel id="pnlEndOfSte pModal" runat="server" cssclass="Modal
          EndOfStepModal Hidden">
          <div class="MediumMo dal">
          <div class="ModalHea der">
          Congratulations , you have completed Step 1.
          </div>
          <div class="ModalScr oll">
          Your progress has been saved to your Journal. You can
          review your journal at any time by
          selecting the "My Journal" link under the RESOURCES
          section of your profile.
          <br />
          <br />
          <h3>Would you like to stop for now, or continue to
          Step 2?</h3>
          </div>
          <%--<asp:button id="btn_logout " runat="server"
          text="Logout" />--%>
          <asp:button id="btnContinue Button_2" runat="server"
          text="Continue" />
          </div>
          </asp:panel>
          <%--path conflict open animation--%>
          <cc1:animatione xtender id="aeEndOfStep Open" runat="server"
          targetcontrolid ="pnlEndOfStepC ontroller"
          behaviorid="End OfStepOpenBehav ior">
          <animations>
          <OnClick>
          <Sequence>
          <StyleAction AnimationTarget ="pnlBlockAl l"
          Attribute="disp lay" Value="block"/>
          <StyleAction AnimationTarget ="pnlEndOfStepM odal"
          Attribute="disp lay" Value="block"/>
          <Parallel AnimationTarget ="pnlEndOfStepM odal"
          Duration=".2" Fps="25">
          <Resize Width="532" Height="400" />
          <Move Horizontal="114 " Vertical="117" />
          </Parallel>
          </Sequence>
          </OnClick>
          </animations>
          </cc1:animationex tender>
          <%--END path conflict open animation--%>
          <%--path conflict close animation--%>
          <cc1:animatione xtender id="aePathConfl ictClose" runat="server"
          targetcontrolid ="btnContinueBu tton_2">
          <animations>
          <OnClick>
          <Sequence>
          <Parallel AnimationTarget ="pnlEndOfStepM odal"
          Duration=".2" Fps="25">
          <Resize Width="1" Height="1" />
          <Move Horizontal="-114" Vertical="-117" />
          </Parallel>
          <StyleAction AnimationTarget ="pnlBlockAl l"
          Attribute="disp lay" Value="none"/>
          <StyleAction AnimationTarget ="pnlEndOfStepM odal"
          Attribute="disp lay" Value="none"/>
          </Sequence>
          </OnClick>
          </animations>
          </cc1:animationex tender>
          <%--END path conflict close animation--%>
          </asp:Content>
          <asp:Content ID="conContent "
          ContentPlaceHol derID="cphDashb oardContent" Runat="Server">
          <asp:updatepane l id="udp_pageCon tent" runat="server">
          <contenttemplat e>

          <div id="FlashConten t">
          Please download the flash player.
          </div>
          <script type="text/javascript">
          var so = new SWFObject("../../dir_flash/demo1b/
          demo1b.swf", "Intro", "640", "480", "8", "#ffffff");
          so.addParam("wm ode", "transparen t");
          so.write("Flash Content");
          </script>

          </contenttemplate >
          </asp:updatepanel >
          </asp:Content>
          <asp:content id="ConButton" contentplacehol derid="cphDashb oardButton"
          runat="Server">
          <asp:updatepane l id="upd_continu e_buttons" runat="server">
          <contenttemplat e>

          <asp:button id="btnContinue Button_1" runat="server"
          text="Continue" Enabled="false" CssClass="Visib le" />

          </contenttemplate >
          </asp:updatepanel >
          </asp:content>
          ----------------------------------------
          END of aspx
          ----------------------------------------

          ----------------------------------------
          BEGIN of vb code behind
          ----------------------------------------
          Partial Class mod_10_20_10_07 0_default
          Inherits System.Web.UI.P age

          Protected Sub Page_Load(ByVal sender As Object, ByVal e As
          System.EventArg s) Handles Me.Load

          If IsPostBack = False Then

          End If

          End Sub

          Protected Sub btnContinueButt on_1_Click(ByVa l sender As Object,
          ByVal e As System.EventArg s) Handles btnContinueButt on_1.Click

          'might require saving user data

          'open modal
          ClientScript.Re gisterStartupSc ript(Me.GetType (), "postBack",
          "endOfStepModal ();", True)

          End Sub

          Protected Sub btnContinueButt on_2_Click(ByVa l sender As Object,
          ByVal e As System.EventArg s) Handles btnContinueButt on_2.Click

          Response.Redire ct("~/page2/")

          End Sub

          End Class
          ----------------------------------------
          END of vb code behind
          ----------------------------------------

          Any suggestions you might have are greatly appreciated.

          Thanks,
          Marc

          Comment

          • Mark Rae [MVP]

            #6
            Re: Post Back and Javascript

            <voidinutah@gma il.comwrote in message
            news:c6d75904-0e5c-46bd-b8e0-9b429d21df12@f3 7g2000pri.googl egroups.com...
            >>Any ideas for this scenario?
            >>
            >Not without seeing your code...
            >
            Here is the aspx page.
            >
            Any suggestions you might have are greatly appreciated.
            I can't see anything obvious, but I'll be the first to admit that I don't
            have much experience in Flash integration

            Hopefully someone else can help you - sorry... :-(


            --
            Mark Rae
            ASP.NET MVP


            Comment

            Working...