Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 30, 2012 09:51 AM by asteranup
Member
8 Points
19 Posts
Apr 26, 2012 07:14 PM|LINK
Hello!!! I use this javascript.
<script language="javascript" type="text/javascript">function EvalSound(soundobj) { var thissound=document.getElementById(soundobj); thissound.Play();}</script>and I play the below success wav file
<script
function EvalSound(soundobj) { var thissound=document.getElementById(soundobj); thissound.Play();}</script>and I play the below success wav file
<embed src="success.wav" autostart=false width=1 height=1 id="sound1"enablejavascript="true">by clicking the below button
<form><input type="button" value="Play Sound" onClick="EvalSound('sound1')"></form>I would like to call the EvalSound function from code behind in an IF statement and play the success.wav filelike thisif (condition){ EvalSound('sound1');} How should I call the function to make it work?
Contributor
5070 Points
1068 Posts
Apr 27, 2012 04:52 AM|LINK
Hi..
In buttom click event try the below code.....
if (condition) { ClientScript.RegisterClientScriptBlock(this.GetType(), "str", "EvalSound('sound1')"); }
All-Star
30184 Points
4906 Posts
Apr 27, 2012 06:59 AM|LINK
Hi,
Welcome to asp.net forum.
You can achieve this by registerstertupscript. You can find many posts below-
http://delicious.com/anupdg/RegisterStartupScript
Apr 27, 2012 07:16 AM|LINK
Hello again!!!
The code ClientScript.RegisterClientScriptBlock(this.GetType(), "str", "EvalSound('sound1')"); doesn't work.
I just see written on my screen "EvalSound('sound1').
Moreover my condition is not related with a button click, it is related with time.
As an example the if statement looks like this
if (hour = 10)
{
play the sound1
}
I haven't study this http://delicious.com/anupdg/RegisterStartupScript yet
20143 Points
3327 Posts
Apr 27, 2012 09:23 AM|LINK
Check the below code!
string display = @"getPasswordRepeatedIndicator();"; if (!Page.ClientScript.IsStartupScriptRegistered("myScript")) Page.ClientScript.RegisterStartupScript(this.GetType(), ",myScript", display, true);
I'm just calling getPasswordRepeatedIndicator(); javascript function!
Hope it helps u...
52 Points
18 Posts
Apr 30, 2012 09:46 AM|LINK
You can use ScriptManager to call js functions from code behind,
Like,
if (condition) { ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "EvalSound", "EvalSound('1');", true); } else { ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "EvalSound", "EvalSound('2');", true); }
Apr 30, 2012 09:51 AM|LINK
sakis297 The code ClientScript.RegisterClientScriptBlock(this.GetType(), "str", "EvalSound('sound1')"); doesn't work.
try this-
ClientScript.RegisterClientScriptBlock(this.GetType(), "str", "EvalSound('sound1')", true);
sakis297
Member
8 Points
19 Posts
How to call a specific Javascript from code behind.
Apr 26, 2012 07:14 PM|LINK
Hello!!! I use this javascript.
vijay_myl
Contributor
5070 Points
1068 Posts
Re: How to call a specific Javascript from code behind.
Apr 27, 2012 04:52 AM|LINK
Hi..
In buttom click event try the below code.....
if (condition) { ClientScript.RegisterClientScriptBlock(this.GetType(), "str", "EvalSound('sound1')"); }My .NET blog
Submit Article
asteranup
All-Star
30184 Points
4906 Posts
Re: How to call a specific Javascript from code behind.
Apr 27, 2012 06:59 AM|LINK
Hi,
Welcome to asp.net forum.
You can achieve this by registerstertupscript. You can find many posts below-
http://delicious.com/anupdg/RegisterStartupScript
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
sakis297
Member
8 Points
19 Posts
Re: How to call a specific Javascript from code behind.
Apr 27, 2012 07:16 AM|LINK
Hello again!!!
The code ClientScript.RegisterClientScriptBlock(this.GetType(), "str", "EvalSound('sound1')"); doesn't work.
I just see written on my screen "EvalSound('sound1').
Moreover my condition is not related with a button click, it is related with time.
As an example the if statement looks like this
if (hour = 10)
{
play the sound1
}
I haven't study this http://delicious.com/anupdg/RegisterStartupScript yet
roopeshreddy
All-Star
20143 Points
3327 Posts
Re: How to call a specific Javascript from code behind.
Apr 27, 2012 09:23 AM|LINK
Hi,
Check the below code!
string display = @"getPasswordRepeatedIndicator();"; if (!Page.ClientScript.IsStartupScriptRegistered("myScript")) Page.ClientScript.RegisterStartupScript(this.GetType(), ",myScript", display, true);I'm just calling getPasswordRepeatedIndicator(); javascript function!
Hope it helps u...
Roopesh Reddy C
Roopesh's Space
Pince
Member
52 Points
18 Posts
Re: How to call a specific Javascript from code behind.
Apr 30, 2012 09:46 AM|LINK
You can use ScriptManager to call js functions from code behind,
Like,
asteranup
All-Star
30184 Points
4906 Posts
Re: How to call a specific Javascript from code behind.
Apr 30, 2012 09:51 AM|LINK
try this-
ClientScript.RegisterClientScriptBlock(this.GetType(), "str", "EvalSound('sound1')", true);Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog