473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
Nov 3 '08 #1
5 4478
<vo********@gmail.comwrote in message
news:4a**********************************@i24g2000 prf.googlegroups.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="MyButton_Click" />
</form>
</body>

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

ClientScript.RegisterStartupScript(this.GetType(), "postBack",
"myFunction();", true);
}
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 3 '08 #2
On Nov 3, 9:51*am, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
<voidinu...@gmail.comwrote in message

news:4a**********************************@i24g2000 prf.googlegroups.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="MyButton_Click" />
* * </form>
</body>

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

* * * * ClientScript.RegisterStartupScript(this.GetType(), "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
Nov 3 '08 #3
<vo********@gmail.comwrote in message
news:7f**********************************@u29g2000 pro.googlegroups.com...
Any ideas for this scenario?
Not without seeing your code...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 3 '08 #4
On Nov 3, 12:44*pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
<voidinu...@gmail.comwrote in message

news:7f**********************************@u29g2000 pro.googlegroups.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_interface/
dir_master_page/DashboardMaster.master"
autoeventwireup="false" codefile="default.aspx.vb"
inherits="mod_10_20_10_070_default" %>

<asp:Content ID="conHead" ContentPlaceHolderID="cphDashboardHead"
Runat="Server">

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

function video_complete() {
if ($get('<%= btnContinueButton_1.ClientID %>').className
== "Visible") {
btn_Continue = $get('<%= btnContinueButton_1.ClientID
%>');
btn_Continue.disabled = false;
}
}

function endOfStepModal() {
var theBehavior = $find("EndOfStepOpenBehavior");
var theAnimation = theBehavior.get_OnClickBehavior();
theAnimation.play();
}

</script>

</asp:Content>
<asp:Content ID="conModal" ContentPlaceHolderID="cphDashboardModal"
Runat="Server">
<asp:panel id="pnlEndOfStepController" runat="server"
cssclass="Hidden">
</asp:panel>
<asp:panel id="pnlEndOfStepModal" runat="server" cssclass="Modal
EndOfStepModal Hidden">
<div class="MediumModal">
<div class="ModalHeader">
Congratulations, you have completed Step 1.
</div>
<div class="ModalScroll">
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="btnContinueButton_2" runat="server"
text="Continue" />
</div>
</asp:panel>
<%--path conflict open animation--%>
<cc1:animationextender id="aeEndOfStepOpen" runat="server"
targetcontrolid="pnlEndOfStepController"
behaviorid="EndOfStepOpenBehavior">
<animations>
<OnClick>
<Sequence>
<StyleAction AnimationTarget="pnlBlockAll"
Attribute="display" Value="block"/>
<StyleAction AnimationTarget="pnlEndOfStepModal"
Attribute="display" Value="block"/>
<Parallel AnimationTarget="pnlEndOfStepModal"
Duration=".2" Fps="25">
<Resize Width="532" Height="400" />
<Move Horizontal="114" Vertical="117" />
</Parallel>
</Sequence>
</OnClick>
</animations>
</cc1:animationextender>
<%--END path conflict open animation--%>
<%--path conflict close animation--%>
<cc1:animationextender id="aePathConflictClose" runat="server"
targetcontrolid="btnContinueButton_2">
<animations>
<OnClick>
<Sequence>
<Parallel AnimationTarget="pnlEndOfStepModal"
Duration=".2" Fps="25">
<Resize Width="1" Height="1" />
<Move Horizontal="-114" Vertical="-117" />
</Parallel>
<StyleAction AnimationTarget="pnlBlockAll"
Attribute="display" Value="none"/>
<StyleAction AnimationTarget="pnlEndOfStepModal"
Attribute="display" Value="none"/>
</Sequence>
</OnClick>
</animations>
</cc1:animationextender>
<%--END path conflict close animation--%>
</asp:Content>
<asp:Content ID="conContent"
ContentPlaceHolderID="cphDashboardContent" Runat="Server">
<asp:updatepanel id="udp_pageContent" runat="server">
<contenttemplate>

<div id="FlashContent">
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("wmode", "transparent");
so.write("FlashContent");
</script>

</contenttemplate>
</asp:updatepanel>
</asp:Content>
<asp:content id="ConButton" contentplaceholderid="cphDashboardButton"
runat="Server">
<asp:updatepanel id="upd_continue_buttons" runat="server">
<contenttemplate>

<asp:button id="btnContinueButton_1" runat="server"
text="Continue" Enabled="false" CssClass="Visible" />

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

----------------------------------------
BEGIN of vb code behind
----------------------------------------
Partial Class mod_10_20_10_070_default
Inherits System.Web.UI.Page

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

If IsPostBack = False Then

End If

End Sub

Protected Sub btnContinueButton_1_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btnContinueButton_1.Click

'might require saving user data

'open modal
ClientScript.RegisterStartupScript(Me.GetType(), "postBack",
"endOfStepModal();", True)

End Sub

Protected Sub btnContinueButton_2_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btnContinueButton_2.Click

Response.Redirect("~/page2/")

End Sub

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

Any suggestions you might have are greatly appreciated.

Thanks,
Marc
Nov 3 '08 #5
<vo********@gmail.comwrote in message
news:c6**********************************@f37g2000 pri.googlegroups.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
http://www.markrae.net

Nov 3 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex | last post by:
Hi!! i have a major problem, and i've been searching for a solution for about 2 weeks, but havent found one. i have to do a POST-Request to a server, but the server shouldnt know my referrer....
5
by: Gary Vidal | last post by:
I have a client side Javascript which checks an OrderQuantityField against a hidden Textbox of the Minimum Order Quantity. I dont want to do validation on a postback. I would like to be able to...
2
by: Matt | last post by:
When we submit the form data to another page, we usually do the following: <form action="display.aspx" method="post"> will submit the form data and open display.asp in the current browser ...
6
by: guoqi zheng | last post by:
In a regular html form, when user press "enter" key, the form will be submitted. However, in ASP.NET web form, a form will only be submitted (post back) when a special button is clicked. Many...
2
by: sunilthk | last post by:
Hi All, I have a question. If javascript is disabled how asp.net determines which control has caused the post back. As we know that when we clicks on the button the buttons name goes with posted...
23
by: Bjorn | last post by:
Hi. Every time i post data in a form the contents are being checked for validity. When i click the back-button, all data is gone and i have to retype it. It's obvious that only a few or none of...
2
by: scotty | last post by:
I have a ListBox with AutoPostBack='True'. The corresponsing form is set as follows: <form runat='server' method='POST' action='results.asp' name='mbrlst_search' ID='search_form'> When...
1
by: Garg | last post by:
I had a listbox, whose autoPostBAck property was set to true. So. if I was clicking on any item for the first time, it caused a successful post-back. However, if i clicked on the item...
2
by: Garg | last post by:
I had a listbox, whose autoPostBAck property was set to true. So. if I was clicking on any item for the first time, it caused a successful post-back. However, if i clicked on the item...
56
by: UKuser | last post by:
Hi, I'm not sure if this can be done as I've searched the web and this forum. I am using an online merchant provider and I must post certain variables to their webforms through a form on my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.