473,569 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4486
<vo********@gma il.comwrote in message
news:4a******** *************** ***********@i24 g2000prf.google groups.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
http://www.markrae.net

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

news:4a******** *************** ***********@i24 g2000prf.google groups.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
Nov 3 '08 #3
<vo********@gma il.comwrote in message
news:7f******** *************** ***********@u29 g2000pro.google groups.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...@markNOSPA Mrae.netwrote:
<voidinu...@gma il.comwrote in message

news:7f******** *************** ***********@u29 g2000pro.google groups.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
Nov 3 '08 #5
<vo********@gma il.comwrote in message
news:c6******** *************** ***********@f37 g2000pri.google groups.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
4425
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. i know it would be quite easy to accomplish this with a simple php-Script, but the problem is that i need the browser (client) to do this POST, so...
5
2150
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 have FormValidate Javascript function postback to my addToCart Method in my code behind function ValidateForm(myform) { if...
2
12539
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 <form action="display.aspx" method="post" target="_blank"> will submit the form data and open display.asp in a new browser
6
3730
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 user get used to click "enter" key to submit a form. How can I use "enter" key to submit/postback in ASP.NET. Thank, Guoqi Zheng
2
2179
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 data, so asp.net can detrmine which btn caused the post back. In case of dropdown lists(if auto post back is true) _doPostback javascript function...
23
14476
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 the visitors will retype it all so i'm asking: "how to preserve POST-data when clicking the back-button?" i've already tried to print post data...
2
2036
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 javascript is enabled, I auto-post the form at the bottom of the .aspx page. It works fine. With javascript disabled, however, the action of the form,...
1
1556
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 subsequently, no post- back occured (because the index of the selected item did not change, hence the click event was not captured). So, to capture the click...
2
6804
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 subsequently, no post- back occured (because the index of the selected item did not change, hence the click event was not captured). So, to capture the click...
56
7195
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 website. The issue is that I need to gauge whether a user has any items in their basket to decide which page I redirect them too. I could
0
7700
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.