How to pass param values from server side to client side scripts

Hi,

I have a page containing a datagrid with a list of geographic positions of interesting places. Users can filter this grid. Clicking an item the system displays the place on a map using MS Virtual Earth map component that exposes a client side javascript api. My problem is that the filtering is done on server side, but the map runs on client side. So during page load, I need to create long strings containing complex javascript codes on the server side, and add it as an event handler attribute to my components. This causes a lot of problems, for exemple I cannot pass variables, only values, like this:  

            String title = dr["NAME"].ToString();
            String text = dr["Comment"].ToString();
            String lat = dr["Lat"].ToString();
            String lon = dr["Lon"].ToString();
            String alt = dr["Alt"].ToString();
            String dateTime = dr["datetime"].ToString();
            String icon = "./Images/Pushpin.gif";
            String js1 = "javascript:addPushPin('" + pinID.ToString() + "', '" + lat + "', '" + lon + "', '" + icon + "', '" + title + "', '" + text + "');";

So I realized that I need a way to pass complex structures, values from server side to client side, in a way that client side scripts will be able to use as params.

I'm a newbie in client programming, is there any best practice for this, or do you have any ideas how to do that?

Thanks a lot! 

Örs

0
wanderlusted
2/21/2007 4:14:13 PM
asp.net.client-side 24353 articles. 1 followers. Follow

4 Replies
932 Views

Similar Articles

[PageSpeed] 27

use a hidden field if data is not sensitive......

1)Make the hiddenfiled runat="server"

2)assign the value of the hidden field at server side.

3)use the value in javascripts.


Let the game begin!!

Barcode image generation made easy.
Writing an ActiveX Control in C#
Generating Relational Data From XML Datatype -Part 1
Generating Relational Data From XML Datatype -Part 2
Dynamic XML From SQL Server
0
imran
2/22/2007 10:24:00 AM

Hi,

Thank you both for your answers! I'm trying to sum up what I've learnt:

Server side:

(0. Design time: creating javascript functions and hidden fields on the page)

1. During page creation I will create my JSON objects containing the params and serialize them into a string somehow 

2. Put this string into a hidden field

3. Add javascript event handlers to my controls 

Client side:

4. When the user clicks the control the javascript event handler is called and gets its params from the hidden field JSON string

 

Am I correct? Is this really the best way to do this? I don't really like these hidden fields, no way to embedd my params in the page in some more elegant way?

Thanks a lot! 

 Örs

 

0
wanderlusted
2/22/2007 12:29:46 PM

Hi!,

You can use Page.RegisterArrayDeclaration("Name","Value") to register a javascript array in server side.

 


Regards
0
kakali
2/22/2007 1:11:59 PM
Reply:

Similar Artilces:

How to pass the client side values to server side?
 hello to All,Actually i wanna implement a code like... a string in HTML textbox retrieve in server side control....suppose i hv a HTML control <input type="text" id="txtHTML"/>, and dis control  txtHTML.text="abc".now i want to retrieve dis client side string "abc" in d server side textbox named "txtASP"...which hs a property runat="server"so please give me an idea how to pass values from client side to server side.... hope u understand a problem... sam.  You could do this <input type="text"...

How to pass values from client side to server side
Hi, Is there a way to transfer variable from a client loop to a server loop. For example: var clitest = 'test'; Now I would like to get test variable from javascript into a server string variable <% sertest = ?? %> I understand that this can be done by storing a variable into a hidden control for example and than access it using server side, but when I have to transfer an array for example it get's a little more complicated. I was wondering is there more efficient approach? You can't transfer arrays, only strings. To workaround this problem pass delimited stri...

how to pass values from client side to server side #2
Hi Guys....               This is Aani....I'm using ASP.NET in C# language.i have created one webpage for get input from user(from java script inputbox).i want that entered data in server side operations.how can i pass that value from client side server side.i need proper code in C# language.reply me soon... Thanks is Advanced... Regards....Aani plz use hidden field.ur assing values to text boxes through java script. before post back call a java scipt function to assign value to hodden fieed. even u can add these ...

passing client side variable value to server side
 i have a grid and  by click on the rows, the onrowclick event is fired on client side. I want to pass the row index to the server side. As there are not sessions variables in javascript so i am stuck to pass the row to the server side.. I have made a texbox and set its valueto the index in the onrowclick event but when refresh calls, the text box became empty as the value set is on client side, i want page to persistthe value,  How can i do that? Tel me some way passing the row index to the server side?? Hi, You can call GridView_SelectedIndexChanging event on row click ev...

Problem passing value client-side to server-side
I have a page that calls a pop-up while passing an encrypted value via a query string. The value is encrypted on the parent client-side in javascript so it needs to be decrypted client-side as well. This decryption occurs on closing the child (popup) and I am at a loss of when and how I should get this value to the server-side. On the popup you just want to process server side code? Anytime you can access for example the raw url:string raw = Page.Request.RawUrl;If you need to access any values on the client side you can access the url using javascript. Another idea is to, on the code beh...

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...

Passing Server Side Control to Client Side Script
Hi All, I have an asp:DropDownList and an asp:TextBox on my form. I want to disable or enable the textbox depending on the selection in the dropdown. I am using master pages and the problem is that when I use the onChange event for the dropdown on the client side, I don't know the ID of the the textbox on the client side to disable or enable it.  How can something like this be done? Thanks,AKA You can use the ClientID property of a control to determine the ID, something like:  <script type="text/javascript"> function ShowMeTheID(){ alert('...

passing data to a server side textbox from client side script
Qu: passing data to a server side textbox from client side java script.Does anyone know how to do this?Thanks,Graham. Remember that when you view an aspx page in your browser, you are viewing straight html code (view the source).  Thus, access the textbox as you would a normal <input type="text> tag.HTH, rchern.Churned Ajax ToolkitPlease choose "Mark as Answer" for the posts that lead you to a solution....

Passing a value from server side to client side without postback
My problem exactly is that on my aspx.vb code-behind, I can update the field using HiddenField ID = "hidSessionTimeout" Code-Behind: on Page_LoadhidSessionTimeout.Value = HttpContext.Current.Session.Timeout on ChangeTimeOutValue()hidSessionTimeout.Value = 5  Client-Side: var x= document.getElementById("hidSessionTimeout"); It seems that the javascript cannot get the latest updated value... Any ideas?    Any Workaround solution? did u keep the page load code in if(!IsPostBack)pavankumar geljian_a:  Client-Side:  var...

Can you pass information from client side script to server side
Is it possible to pass information from client side to server side without the use of cookies? i am creating textbox's that i generate in a loop that are displayed to the screen and i need to access the values in those boxes. I can get them with javascript but dont know how to use asp to get them??? thanks The last sample on this page shows how your client-side script can send information back to your server-side code. I hope this helps.Alister...

Client side code to pass values to server side variable?
Hi there, I have ListBox_SelectedTextChanged() method that creates another list box in the runtime as follows: // Get Action Level List lbxActionLevel = new ListBox();lbxActionLevel.ID = "ddlA" + i.ToString(); lbxActionLevel.Width = 100; lbxActionLevel.Rows = 2;SqlDataReader dr = new BusinessLogicLayer().bllGetActionLevels(); lbxActionLevel.Items.Clear();while (dr.Read()) {ListItem lAction = new ListItem(); lAction.Text = dr.GetString(1).Trim();lAction.Value = Convert.ToString(dr.GetInt32(0)); lbxActionLevel.Items.Add(lAction); lbxActionLevel.SelectedIndex = 0; } I ...

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...

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....

Issue obtaining values in server-side from dropdownlist when updating value using client-side script in master page
HiI got a page in a contentplaceholder of a master page. There is two pulldowns. I populate the first one using server side coding and then use client-side javascript. So far so good. The issue is that upon a postback I try to collect the select value of the second pulldown and there is no data in the pulldown and no selected item. I tried using control.selectedvalue (nothing) or searching the form controls Stringvariable = oForm.FindControl("Control")Thing is I've done this before in 1.1 outside of a master page and it works.Thanks in ad...

Web resources about - How to pass param values from server side to client side scripts - asp.net.client-side

Seal script - Wikipedia, the free encyclopedia
Seal script ( simplified Chinese : 篆书 ; traditional Chinese : 篆書 ; pinyin : zhuànshū ) is an ancient style of Chinese calligraphy . It evolved ...

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: The Force Awakens’ script reveals answers to our burning questions
... will make us wait until May 2017 when Episode VIII is set to premiere to learn anymore details about them. In the meantime, the official script ...

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 ...

Studio: Tupac Shakur film script was offered by hacker
"Celebrity hacker" allegedly accessed more than 100 email accounts of actors, athletes and media personnel and tried to sell unreleased scripts ...

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/15/2016 5:10:24 PM