Server side Generating and client side executing javascript


 This is a really basic question.  If one has a piece of code on the server side that generates some javascript, how do you inject and execute this script n the client side?  For example, I have a server side function that inserts a bunch of calls to a the javascript function foo(), such as foo(1); foo(2);.....How can insert these calls into my webpage so that they are executed on a periodic basic.  I assume I would use an script manager tag, and inside this tag I would have an update panel, but am unsure where to go after that.



2/5/2007 3:37:18 AM 13973 articles. 1 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 23


you can insert javascript code to a page with the object "Page.ClientScript", e.g.:

if (!manager.IsClientScriptBlockRegistered("somecodefile.js"))
  manager.RegisterClientScriptInclude("somecodefile.js", scriptBlockName);
Or you create javascript inside the block:
private void CreateOnMouseOverHandler()
   ClientScriptManager manager = this.Page.ClientScript;
   if (!manager.IsClientScriptBlockRegistered(JS_ONMOUSEOVERHANDLER))
	StringBuilder scriptBlock = new StringBuilder();
	scriptBlock.Append("function " + JS_ONMOUSEOVERHANDLER + "(source, hiddenFieldName, offImage) {\r\n ");
	scriptBlock.Append("\ = 'hand';\r\n");
	scriptBlock.Append("\tvar checked = document.getElementById(hiddenFieldName);\r\n");
	scriptBlock.Append("\tif(checked.value == 'True' && offImage.length == 0)\r\n");
		and so on ...
	manager.RegisterClientScriptBlock(this.GetType(), JS_ONMOUSEOVERHANDLER, scriptBlock.ToString(), true);
Marc Andre
2/5/2007 6:19:33 AM

Similar Artilces:

executing server side code and client side (javascript) code simultaneously while clicking a button
how to execute server side code and client side (javascript) code simultaneously while clicking a button in You can't. When clicking a button: the client-side executes, the page does a PostBack, then the server-side executes.NC... what if i want to update a database and then open a new windows is it possible with

Execute the client side and server side code
Hi, Hi, I have two drop down lists one ddl1, ddl2. when ddl1 index is changed I have to change the label before the ddl1 and contents of ddl2. 1) to change the label before ddl2, I am using the javascript like this:ddl1.Attributes.Add("onchange", "changeLabelText(this); return false;"); Javascript function<script language="javascript"> function changeLabelText(ddl) { var indx = ddl.selectedIndex; var lbl = document.getElementById('<%= lblSelect.ClientID %>'); if(indx == 0) lbl.innerHTML = "Select A:"; if(indx == 1)lbl.i...

javascript execution after side server side code
I have a dropdownlist selected change event (server side). I need to execute a java script code after that server side event. how to achive this ?? I used Response.Write("<script>alert('hi')<script>"); . but its not working and all the form alignment was getting disturbed. is their any other way to achice this??     ThanksPrashanth.J Use RegisterClientScriptBlock method to execute javascript methods "at server-side"May the Force be with you Never use Response.Write except in debugging situations, because it will mess ...

Server-side execution vs. client-side
Hello, I am doing aspx web programming using vb in MS Visual Studio.  I am trying to make my program to when the user clicks on a button that my program launches another software package that we own (in this case the other software package is called Syteline).  The way that I am trying to accomplish this is via the CreateObject function route.  My program is running on the web server.  While I am sitting on the server that contains this Syteline application, I open up Internet Explorer and launch my web program.  When I click on the button, it gives me ...

Client side to execute server side code
I am maintaining an ASP.NET C# application written by someone else.  I am essentially a newbie to web development especially client side stuff.  Based on reading these forums I understand that I can't directly call a server side method from the client side and I have to use post pack in some way (using a webservice is not an option here).  My confusion comes from the HTML setup being used.The page has three frames; a header, body and footer.  Each frame is filled by it's own ASPX page.  The footer contains buttons for navigating to another page and some of the b...

server side variables in client side javascript
I want to use an variable in client side javascript.In regular asp I used hidden fields.what is the best way to do this in ASP.NET ?thx,Intersee my blog at and check the future of open mobile widget solutions at By and large, I personally still use Hidden fields to store information, that either my Javascript function or my code-behind use.  I barely use the RegisterScriptBlock method(s) and that is only for situations where I want to be really dynamic with the client side functionality.  95% of the time, I can still use a...

Firing both Client side event and server side event for server side button
I am having some difficulties getting this to work.. I have button_click ( and ClientClick (Javascript).  Javascript is firing fine.  Server script is not. may be you have return return false in the in the javascript which is why its not firing server side event.You should add javascript evelt like thisbutton1.onclientclick = "functionname" Function should nopt return false. Vikram www.vikramlakhotia.comPlease mark the answer if it helped you...

How to call server side function from client side JavaScript?
I want to call a server-side function, like a button's click event or just another private or public function , from a client-side JavaScript function. How do I do that? thanX AnzIf this post was useful to you, please mark it as answer.ClientSideAsp.Net | Blog Maybe alittle more that you need, but....... 1) Put a button on the page. Lets say its id is Button1. Make sure that its has causesValidation=false 2) Write the code for the button. 3) Write the following in the PAge_Load event Button1.Attributes.Add("onClick", "myJSFunction(); return false") 4) Copy this javascript onto your page. function myJSFunction() {         //Fix to get the button to validate the page         if (typeof(Page_ClientValidate) == 'function')         {                 Page_ClientValidate();         }         if (Page_IsValid)         {                 var answer = confirm('Do you wish to continue?');                  if (answer)                 {                     &...

reading data at client side which is generated on server side
Hello, I am developing an application in which MS word templates will be on client side. The data will be read from the database and sent to client side. This data has to be entered in the word documents which will generated from the template. questions 1) In what format shud I send the data to client side? 2) how the client side script will read the data and place it in the word document at a proper place? Thanx AFAIK, if you make a form in word, you should be able to access all input places by program. Well, the problem could be, you can do this on the server,...

Jscript, moving from client-side to server-side (.NET)
Hey all I’m working translating a web-app written in client-side Jscript to run on the server-side as JScript.NET. Without needing to get too specific, I am using Jscript because the original page aggregated raw data to produce statistical results (this was done dynamically based on user 'sort-by' options). The final output is an html report that can be emailed. Because this is currently being done on the client side, as the raw data grows the load-time grows as well (to the point that has almost become unusable). I’m posting here to see if anyone has any experi...

executing my own function @ server side for a client side event
hi all, I have a client side dropdownlist control with onchange event. I am calling form1.submit() method in onchange event. is it possible to catch that event at server side ???ThanksPrashanth.J Not if you call form1.submit(). Try replacing that with <%= ClientScript.GetPostBackEventReference(DropDownList1, string.Empty) %>; Then in the Page_Load handler server-side: private void Page_Load(object sender, System.EventArgs e){ if ( this.IsPostBack ) {  // Place any code that needs to be executed ONLY on a post-back here.  string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"];   if ( eventTarget == DropDownList1.ClientID )  {   // It is from the dropdown...  } }} Of course replace "DropDownList1" with the real DDL. NC... Thanks NC...ThanksPrashanth.J...

Execute Client-side binary from server-side vb?
To preface, this is a research project with little to do with a production environment. I need to allow a server-side ASP script to execute a .exe binary on the client machine. Example: I login to a webpage, click on the 'Do some Work' buttonIt spawns an arbitrary executable, maybe MS Word.  After which the server-side script is  unconcerned to that process. From what I've read an ActiveX control is one route but requires a legally signed certificate and appropriate permissions in the browser.  Any help or shortcut? Thanks so much in advance,Joseph you can do s...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in ( required field, range validator and others) question is the required field validator is a server side control. So does that mean that it does a post back? it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

Passing parameter from Javascript(client-side) to server side
Hi guys, I'm having problems with my code. I have a textbox1 and a submit button and another textbox2. When my user enters a value into textbox1 and click submit, the description text should be returned to textbox2. Here's my code: Javascript(client side) : function CheckValue() { var stdNo = document.getElementById('Textbox1'); if (stdNo.value != null) { What to code here to pass the parameter value to my server?? } "TextBox1" runat="server"> "Button1" runat="server" OnClientClick="CheckValue(...

Stop execution of server side event from client side
Dear All  I have a text box and i wrote code on the server side event( On Text Change). So when i write something on the text box it goes to server and execute the server side code. Now i want to control this sever execution from client side. i mean i want to cancel this postback from client side under some conition. can anyone plz help me? Regards Sure if you let us know what you want to be done. here is an example <asp:textbox id="txtFile" OnTextChanged="javascript:RefreshPage();" Visible=true Width=500 Runat=server/> function RefreshPage() {    //Do something}Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations THis is my text box <asp:TextBox ID="TextBox1" runat="server" onchange="CancelPostBack()" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox> THis is my server side code protected void TextBox1_TextChanged(object sender, EventArgs e) { //Any code} THis is my client script code <script type="text/javascript" language="javascript" >function CancelPostBack() { //for a particular condition i want to cancel the post back here //But i dont know how to cancel the post back so that the text of the box will chage but will not go to server } </script>   Hi then you can just straigtaway use my code, e...

how to call server side function from client side javascript?
Hi all, I have a image button in the update panel. I would like to call a method from server side (not from webservice) to get the variable when Onclick on the image button is invoked. Is there any way that I can able to access this function from the client script? In using the UpdatePanel, in essence, you're already doing this because there will not be a full postback.  You can make an asynchronous call to your Click method of your ImageButton.  So, what do you want to do with this "variable"?Christopher Reed"The oxen are slow, but the earth is patient."...

Call server side function from client side javascript
I have a javascript where I either need to call an onclick even of a server link button or I need to be able to call a server side function.   The only thing is I cant use AJAX.  Is there any way I can do this or am I spinning my wheels. Thanks!-------------Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue. I have a similar problem.  In my case, I would like to set a server-side session object from JavaScript.  Any suggestions?  Thanks.  Dan Sure, you can do that.  If you just want to call a click event of a button, you can do it like this: var btn = document.getElementById('LinkButton1'); if(btn == null) alert('Button not found!'); else; And if you want to call a server-side function, just setup an invisible button: <asp:Button ID="Button1" runat="server" style="display:none;" /> And in the code-behind for that button, call your server-side function (and then use the javascript snippet above to invoke this event handler): Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 'Call your function End Sub Hope this helps!  Please mark the helpful post(s) as Answer.Josh Stodola ← Come check out my blog! Spafa and Dan-Josh has posted a very unique ...

When To Use Client Side vs Server Side vs AJAX
Before AJAX, it was fairly clear to me where to draw the line between functionality best performed server-side vs client-side.  For example, database access and data processing is done on the server, and basic field validation and other UI stuff is done on the client.  But now with AJAX implemented through Atlas, the line is blured.  I know what can be done... but what is the optimal way to design a web application using Atlas (in terms of what functionality should be implemented server-side versus client-side versus Ajax)?  What is the prev...

Dear all, I made my own autoComplete extender because the standard one was not suitable for us... I have a problem to returning a property value of my extender that was changed on the client-side. I used the default extender template in order to create it. Does anyone knows how to update a property on client-side and get its value on the postBack? Normally the GetPropertyValue of the ExtenderControlBase should pick the value from client but it returns the default value on null... Please help me... Thank you very much Hi Have you or anybody else managed to find a solution for this...

Instantiating an object of a server-side class in client-side JavaScript
Sorry this might be an easy question, but I couldn't find how to do this.I want to define an object like,var myObj = new MyServerSideClass(); MyServerSideClass is defined in the cs code. Is this possible? If it is, how? Thanks in advance.  Checkout the Example of Passing and Returing Complex Types in this doc: Live .NETKazi Manzur Rashid (Amit)_________________________Web: http //dotnetshoutout.comBlog:

When to use client side varidation and server side varidation in .net?
In .net or classic web application we can varidate user data either on client isde or server side. How to select which side varidate to be used? Thanks! Generally, I use both client and server validation. I make sure the input is in the correct format and reasonably valid on the client, then I verify the data on the server. The extent of validation also depends on the type of data that I need to validate.Here are a few references:Validating ASP.NET Server ControlsIntroduction to Validating User Input in Web FormsClient-Side Validation for ASP.NET Server ControlsSecurity Checklist...

Accessing server-side Datatable object from client-side javascript?
I am working on a control  that generates 2D charts (line,bar,pie,etc) using VML (for now) to draw the charts client-side. I am new to Javascript and still cant figure out how to access the data I need to graph from the javascript side.  I am currently using a Sys.Data.Datable on the client side as test data (building the table manually in javascript) and it works fine but I cannot figure how to pass a datatable from the server to the control extension behavior? I have read/seen code on the forums on how to do this using a web-service but I am really looking at a more generic approach where people could just bind a datatable to the control via the properties or in code so they can use their business logic layer functionality without having to write web-services. Let's say I have the name of the page object/variable holding the datatable (from properties of control) how would I access this object as a Sys.Data.Datatable in Javascript? Would I need to use some kind of converter? (hope I explained myself correctly and  this makes sense to someone hehe)   Thanks in Advance Pascal Hello Pascal: > I am new to Javascript and still cant figure out how to access the data I need to graph from the javascript side. Strictly speaking, you can't! It is the server-side code that renders client-side code, so what you can do is actually the reverse: write the datatable to javascript. Here is a topic that can give s...

Client vs. Server Side AJAX.Net
I am curious to know what the advantages and disadvantages are to using the client side declarative style AJAX controls vs. the server side.  I can't seem to think of too many reasons why I would go to the client side libraries when I can use all the power of ASP.NET (debugging, compiling, controls) and just wrap them in a UpdatePanel.   It also seems kind of counter productive to use the client side libraries because they don't utilize all the cool new developments of ASP.NET.  Am  I missing something?  Do the client AJAX libraries give you more flexibility?  Can the two, client and server libraries, be used together in one site?  Just curious to see how people are using one vs. the other and the benefits.  Thanks-   Hi,while everyone has got its opinions and feelings about the server-centric and client-centric programming models, IMHO one thing must be stated clearly: all the MS AJAX stuff is built on top of the client-side library, from the UpdatePanel to all the Control Toolkit extenders (that wrap special client-side components called "behaviors") to the drag and drop functionality, templated client controls, bindings, transformers, declarative syntax, animations...The power comes from the client-side library :) Alessandro Gallo | Blog | My book: ASP.NET AJAX In Action IMHO with the server side approach using UpdatePanel you have more productivity, because you can work as...

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@ Thanks, May I say, when an user clicks a button, pop up box show up. are they communicate? When User Clicks on Button, a popup comming means, on that Button onclick event you might have some Client Side JavaScript. That's why you got popup. So are they communicate? As Browser will act for onclick event, message box shows up. Is click and Sever on sommunicating for this. No it's puerly client side event. But some times, when you click button it submitts to server and does some process as you needed and get's the results back, in that instance you can think browser send request to server and server process it and responds back to browser. hope I made it clear to you!  Sreedharhttp://www.w3coder.orgweblog

Web resources about - Server side Generating and client side executing javascript -

Vogtle Electric Generating Plant - Wikipedia, the free encyclopedia
... / 33.14333; -81.76056 Coordinates : 33°8′36″N 81°45′38″W  /  33.14333°N 81.76056°W  / 33.14333; -81.76056 The Alvin W. Vogtle Electric Generating ...

Ivanpah Solar Electric Generating System - Spring 2013 - a set on Flickr
... Commons Getty Collection Galleries World Map App Garden Camera Finder The Weekly Flickr FlickrBlog Upload Sign In Ivanpah Solar Electric Generating ...

Generating Electricity By Walking - Google Science Fair 2014 - YouTube
Did you know that you can produce electricity by just walking? Here's my documentation of the gizmo that I've conceptualize over the years. It's ...

Generating media attention was the aim of New York Times attack: Akamai
Cyber attacks, such as the recent one on the New York Times, are more about gaining attention than causing damage, according to Akamai.

Holiday tax generating more money than ever intended
THE $55 tax everyone pays when they leave Australia will generate more than $1 billion next year but tourism operators say it’s nothing more ...

FourPlay review: Generating momentum with improvisation and surprise
From string quartet into a rock band 19 years ago and FourPlay is presenting `interesting compositions, with finely detailed arrangements', John ...

Men In Kilts generating cash and kudos
The Men In Kilts window cleaning concept might seem like a gimmick, but Tressa Wood's business smarts have the company cleaning up, and landed ...

Live blog of MagNet2013 Conference: Generating Publicity—The Right Way
Live blog of MagNet2013 Conference: Generating Publicity—The Right Way

Generating interest in homegrown power
Generating interest in homegrown power People's Daily Online ... are dealing with the preliminary paperwork. "The method was absolutely new ...

IHG generating over $20 million a month in revenue from mobile bookings
InterContinental Hotels' emphasis is on developing booking apps and mobile features to engage with guests in every step of their journey.

Resources last updated: 3/24/2016 9:42:25 PM