No, I am not planning to call from button click.
Like, My javascript function name is Popup().
now my code on aspx.cs is like
if(condition)
{
I want to call popup() function from javascript.
}
Main Topics
Browse All TopicsI have Popup() function in Javascript. How can I call this function from ASPX.cs code behind file ? Can I directly call Javascript function from my C# code behind. Thanks in advance.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
No, I already have tried that.
How can that will work, actually "Page.RegisterStartupScrip
Thanks again.
I have done it like this before
Set the Body tag in your page/master page to runat="server" and an id="MainBody".
Put the script tag in your page like you normally would with any HTML file
<script src="popup.js" type="text/javascript"></s
Then in the code behind attach the onload attribute to the body tag .
protected void Page_Load(object sender, EventArgs e)
{
MasterPageBodyTag = (HtmlGenericControl)Page.M
MasterPageBodyTag.Attribut
}
There will be some event for which you want the particular javascript need to fires. Since you want your javascript to fire when a particular condition satisfy. I can suggest you add the particular javascript on the page load event.
Code snippet will be like this.
web.aspx
<body id="Body" runat="server">
Code Behind file
if ( condition )
Body.Attributes.Add("Onloa
else
Body.Attributes.Remove("On
Or if you are using Master Pages where the body tag is in the Master Page. but only some of the content pages need to use the javascript.
You put this is the content pages that use the javascript.
protected void Page_Load(object sender, EventArgs e)
{
MasterPageBodyTag = (HtmlGenericControl)Page.M
MasterPageBodyTag.Attribut
}
Put javascript tags around a literal control.
<script language="javascript">
<asp:literal runat="server" name="javlit1"></literal>
</script>
Then in your if statement, write the javascript you want to run to the control. When the page renders it will run your javascript and allow you to popup your window.
I.E.
If (condition is met)
{
this.javlit1.text="alert('
}
Remember to clear the literal control on page_load, and to register your literal control.
Cheers
Greg
Calling Code behind Function in java script [1- using page method ]
http://ledomoon.blogspot.c
Business Accounts
Answer for Membership
by: jeebukarthikeyanPosted on 2006-12-26 at 11:02:00ID: 18199169
Hi ,
lick","ret urn javascriptfunctionname();" );
if ur planning to call a javascript within in a button control
then
btnAdd.Attributes.Add("onc
//javascriptfunctionname name the function u need to call
b u d d h a