How to call a client side script from a server side script?

Hi guys,

I have a Button1_Click function which gets executed on the server side as soon as Button1 is clicked. I have a client side function, test, which is  written in vbscript. I need to call this test function from the Button1_Click function. Can anyone of you please tell me how to do this?

The test function is inside an asp:content tag (Please excuse my terminology if I am wrong, I am new to all this). 


Thanks and Regards,

RJ

0
raji80
2/8/2007 8:26:28 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

6 Replies
1690 Views

Similar Articles

[PageSpeed] 42
Get it on Google Play
Get it on Apple App Store

Have you tried to use the below code

Button1.Attributes.Add("onclick","test()");

HC


Haissam Abdul Malak
MCAD.NET
| Blog |
0
Haissam
2/8/2007 9:39:25 AM

Yes, I have tried that. But the reverse of what I have asked is happening. With the code that you have given, the client side script is getting executed first and then the server side script is getting executed. I want the other way. Is that possible?

 

Thanks and Regards,

RJ

0
raji80
2/8/2007 10:32:54 AM

on buttom1_click event use the below code

Page.RegisterStartupScript("click","<script language=javascript>test();</script>");

this will fire after the button click is fired.

HC


Haissam Abdul Malak
MCAD.NET
| Blog |
0
Haissam
2/8/2007 10:42:39 AM

This is fine. But what I actually wanted to do is, I want to go to the server side script after clicking a button, then execute some code there and then call the client side function, execute some code there and then come back to the server side function to execute some more code there and then may be again go to the client side function and so on. Is it possible to move freely like this between these two kinds of functions (server side and client side)?

 

Thanks & Regards,

RJ

0
raji80
2/8/2007 11:24:51 AM

u must understand the defrence between server side and client side:

to excute server side u need to postback (or ajax witch is postback) and client side is made on the client machine (without knowing nothing about the server)

going back and forth like this is not recomended caz it can do  alot of postbacks (flashing screen)

u can put your client script throw the server side by using <%=eturnVBScript()%>

or u can change your vbs code throw server side

(i use javascript)

&nbsp;</P> <P>&lt;script ...&gt;</P> <P>funcation doublealert()&nbsp;</P> <P>{</P> <P>alert(&lt;%=geta()%&gt; + &lt;%=getb()%&gt;);</P> <P mce_keep="true">&nbsp;</P> <P>}</P> <P>&lt;/script&gt;</P> <P mce_keep="true">

or even u can use:

this time c#

</P> <P>string myscript=@"&lt;script&gt;...</P> <P>...</P> <P>serversidevaluetoget="+serversidevalues()+ @"</P> <P>....</P> <P>..</P> <P>&lt;/script&gt;";</P><FONT size=2> <P>ClientScript.RegisterStartupScript(</FONT><FONT color=#0000ff size=2>typeof</FONT><FONT size=2>(</FONT><FONT color=#2b91af size=2>Page</FONT><FONT size=2>), </FONT><FONT color=#a31515 size=2>"yourscript"</FONT><FONT size=2>, myscript</FONT><FONT size=2>);</FONT></P> <P><FONT size=2>

 

p.s hope it helps and wasn't a total nonsance

0
folen
2/8/2007 11:46:19 AM

u must understand the defrence between server side and client side:

to excute server side u need to postback (or ajax witch is postback) and client side is made on the client machine (without knowing nothing about the server)

going back and forth like this is not recomended caz it can do  alot of postbacks (flashing screen)

u can put your client script throw the server side by using <%=eturnVBScript()%>

or u can change your vbs code throw server side

(i use javascript)

&nbsp;</P> <P>&lt;script ...&gt;</P> <P>funcation doublealert()&nbsp;</P> <P>{</P> <P>alert(&lt;%=geta()%&gt; + &lt;%=getb()%&gt;);</P> <P mce_keep="true">&nbsp;</P> <P>}</P> <P>&lt;/script&gt;</P> <P mce_keep="true">

or even u can use:

this time c#

</P> <P>string myscript=@"&lt;script&gt;...</P> <P>...</P> <P>serversidevaluetoget="+serversidevalues()+ @"</P> <P>....</P> <P>..</P> <P>&lt;/script&gt;";</P><FONT size=2> <P>ClientScript.RegisterStartupScript(</FONT><FONT color=#0000ff size=2>typeof</FONT><FONT size=2>(</FONT><FONT color=#2b91af size=2>Page</FONT><FONT size=2>), </FONT><FONT color=#a31515 size=2>"yourscript"</FONT><FONT size=2>, myscript</FONT><FONT size=2>);</FONT></P> <P><FONT size=2>

 

p.s hope it helps and wasn't a total nonsance

0
folen
2/8/2007 11:47:07 AM
Reply:

Similar Artilces:

Call server-side script from client-side script
Hi to all, I would like to ask you How can i call from client-side script a server-side script and to have the result from the server-side script in the client-side script. For example, i wand to call a function writing in server-side (DynaScript) script from a client-side script (JAVASCRIPT) and to have an answer from the function. Thanks in advance. Nick, One way that you could get round this is to write your client script code as you would server script eg. <SCRIPT language=javascript> function getValue()... would be written as: <% psDocument.WriteLn(&...

client-side scripting or server-side scripting
I want to perform data validation in my page using javascript before the data is sent to my server, but I am very confuse that I don't know which way to perform, client-side validation or server-side validation? My javascript bible told me that javascript is a client-side scripting for data validation in client pc, but when I look in my asp.net bible, the validation part is done at server side. The worst is that, I find no way to use javascript in .asp or .aspx environment. I am really confuse with all these, could any one help me on this? Thanks. Use .NET validator co...

client side script Vs Server side Script
Which is better ? Using Client Side validations with Java Script or Using Server Side validation controls provided in asp.net You should use both... Client-side for a rich user experience and server-side to support browsers without javascript support or with javascript turned off....

Client-Side scripting vs Server-Side scripting
hello I need an article that spaeks about Client-Side scripting vs Server-Side scripting,and when i need to use one of them thank you for the help and for the time here are some good links to a bunch of articles on that subject...

Difference between client side scripting and server side scripting
Hi,      Can u  plz, explain why the server side scripting is necessary, inorder to write the client side scripting. What is the main difference between the client side scripting and server side scripting. Client-side scripting is code that is executed on the client side, such as JavaScript. Server-side scripting is code that is executed on the server, such as VB, VB.NET, C#, or J#. For a better definition of server-side scripting and when it's necessary, please visit http://en.wikipedia.org/wiki/Server-side_scriptingRyan OlshanASPInsider | Microsoft MVP...

Calling server side scripts from client side
Hello, Can Anyone help out from the following : It is regarding calling server side scripts from client side events. I am able to instantiate a jaguar component in the server side script written in the body of the HTML page as follows : <% var mycomp = java.CreateComponent ("pkg_dispatch/n_jaguar", "iiop://jaguar:9000", "Jagadmin", "" ); if (mycomp == null) { document.writeln("ERROR: failed to instantiate !"); return; } %> I want to use the instance of the jaguar component else wher...

Client side script calling Server side functions
Hi, I'm currently developing an ajax.net enabled aspx page that contains a usercontrol (which is based on the listbox but extends it to include icons to represent invalid data). http://www.djcharlie.co.uk/WeeeCareResolutionCentre.jpg I want the onClick event of the selected TR to call an asp.net server function which then populates the controls to the right hand side in the page. Obviously because the row is just rendered HTML overriden from the base class I can only assign a javascript function to the onClick event. So I need a way of calling a server side function that will populate th...

calling server side function from client side script
i have a web form that includes a function named "koko()" in its server side class i want to write a script code in in its HTML script that will be run at the client side, and this client side script will call the function "koko()" from the server side. in brief : i want to call a server side function from a client side script... can you help me in this You can't call server-side code directly from client-side code. You can, however, trigger a postback that your server-side code watches for and triggers the server-side code appropriately. You can do some ...

Acessing Variable, declared in the client side script, from the server side script
I'd like to know how can I use variables declared in the client side script from the server side script. Thanks! You cannot. The only way is to pass them as arguments to the server-side script. -- Larry Cermak [Team Sybase] Corporate Technology Partners EAServer Training & Consulting Coming Soon: Web DataWindow Book Web DataWindow Articles: http://my.sybase.com/detail?id=1003371 "Jeong-Su, Hwang" <hjs@i4biz.co.kr> wrote in message news:s9YmFSfKAHA.201@forums.sybase.com... > I'd like to know how can I use variables declared in the cl...

Acessing variables, declared in the server side script, from the client side script
I'd like to know how can I use variables declared in the server side script from the client side script. P.S.: I'm using JavaScript in the server side script and in the client side script. I don't like to use ASP. Thanks! One example that come to mind: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content="text/html; charset=windows-1252" http-equiv="Content-Type"> <META name=GENERATOR content="MSHTML 5.00.2919.6307"> <SCRIPT language=JavaScript> ...

communication between client side(java script) and server side in .net project
I have a question which is, when building a .net project, we are able to use server side code and client side code(java script). How do they communicate? Thanks Client Side coding works with the WebBrowser. So when ever you write client side code you have to keep browser compatability in your mind and you have to code. Server Side code works with Web Server (IIS) and it's ASPNET ISAPI's. The won't directly communicate with each other. But using AJAX you can all server side code from Client Side! Example article on Ajax@ http://www.devarticles.com/index2.php?option=content&task=...

Calling a client side script from web server control
I have an image button server control on a page, i need when i click on it to call the client side script which will add a new row to an HTML table on the same page. but it always ignore the script and nothing happen. any idea plz, thank u. here is the script am calling onclientclick with the image button<script type="text/jscript" language="javascript" > function addtoTable(){ var oRow = document.createElement("TR"); var oCell = document.createElement("TD");var CONT1 = document.createTextNode("TEST"); oCell.appendChild(CONT...

How do I call server side function in client side script without using __doPostBack
Hello, My page has a server side panel that is hidden when the page loaded, checkboxes inside of the datagrid, and buttons.  If at least one checkbox is not clicked and the user click on the button, I show the panel.  When the user click on one of the checkbox, I want to hide the panel.  Onclick on the checkbox I already have a cleint function to change the row color.  I don't want to use __doPostBack.  Don't want to do postback. My question are: How do I either have checkbox onclick called both client and server side functions.  Or have the client side func...

Client-Side and Server Side Scripting
Hi, im currenty in the process of trying to get an asp.net page to work with both <script> and <script runat="server" tags... idea being, i have a <script> tag which holds all the client side scripting for my webpage, at the moment this is just some slider controls which i have created (the scripting behind this is actually from someone on a different forum, which i have modified to do what i want..) - but i also want a <script runat="server"> tag to hold all the code for the buttons pressed etc in my web-page. im trying my hardest not to use a ...

Web resources about - How to call a client side script from a server side script? - asp.net.web-forms

Script (typefaces) - Wikipedia, the free encyclopedia
Casual scripts show a less formal, more active hand. The strokes may vary in width but often appear to have been created by wet brush rather ...

Bahamas man accused of hacking celebs, stealing movie scripts & sex tapes
... who stands accused of hacking into the e-mail accounts of celebrities and entertainment studios, then trying to sell off unreleased scripts, ...

‘Star Wars: Episode VIII’ script is so incredible that J.J. Abrams now regrets not directing it
The range of emotions sparked by Star Wars: The Force Awakens is quite vast. While some moviegoers thought the film was an absolute triumph, ...

Gilead Sciences, Inc. Faces Troubled HCV Scripts as AbbVie Inc Scripts Go Up
Gilead HCV prescriptions decline, while AbbVie sees an increase in HCV scripts.

Google Apps Script: Tracking add-on usage with Google Analytics
... blog Posted by Romain Vialard, a Google Developer Expert and developer of Yet Another Mail Merge , a Google Sheets add-on. Google Apps Script ...

​Man charged with hacking celebs' emails, stealing scripts
Prosecutors say Bahamian man tried to sell unreleased movie and TV scripts and private sex tapes he stole from celebrities' email accounts

Bulls flip the script in stunning Christmas Day victory over Thunder
Chicago Tribune Bulls flip the script in stunning Christmas Day victory over Thunder Chicago Tribune The Bulls swept away their negative vibes ...

The Hateful Eight Ending Differences from Script Revealed - Collider
Brian Formo attended a live read of 'The Hateful Eight' in 2014 and he reveals all the ending changes from Quentin Tarantino's script to the ...

John Boyega Says Star Wars Episode VIII Has A Much Darker Script
, then Episode VIII will take cues from The Empire Strikes Back, adopting a darker tone, according [...]

The police protection playbook: how Ohio officials followed the script to the letter
The day ended with impassioned calls for calm; that Cleveland and Ohio residents be respectful and mindful of the process and the inevitable ...

Resources last updated: 1/16/2016 1:51:37 PM