Sending array data with hidden input field from client side to server side

I have some values that I'm sending with javascript to the server side code via a hidden input field.  This works great.  However, I want to find an elegant way to split the values up on the server side.  What I have below works, but it doesn't seem like a very clean solution. 

Client code

var values = '&approved=1&funded=0&winprob=2';

document.form1.ipHidden.value = values.toString();

Server code

Dim strValues As String = ipHidden.Value.ToString()

Dim strApproved = strValues.Substring(strValues.IndexOf("approved=") + 9, 1)

Dim strFunded = strValues.Substring(strValues.IndexOf("funded=") + 7, 1)

Dim strWinProb = strValues.Substring(strValues.IndexOf("winprob=") + 8, 1)

 

As you can see I'm passing the values similar to how they'd be passed in a QueryString.  Is there a way to take a string like "strValues = &approved=1&funded=0&winprob=2" and get the values for each key similar to using the QueryString.  ie.  strApproved = strValues.QueryString("approved")

Thanks for any help.

Kent

0
kent
1/23/2008 8:27:04 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

3 Replies
874 Views

Similar Articles

[PageSpeed] 59

You can split strValues whenever @ character exists

strValues.Split('@') which will return a string array containing 4 items 

    1- Nothing

    2- approved=1

    3- funded=0

    4- winprob=2

And you can assign each string to its specified value in the returned string array

HC 


Haissam Abdul Malak
MCAD.NET
| Blog |
0
Haissam
1/23/2008 9:07:42 PM

I understand how Split will return a string array, butI still don't understand how to get at each value without looping through the array and testing for the existence of the key I want the value for.  Is the following the best way to get at these values?  Or could the string array be loaded into a SortedList easily?  Then I could just reference the SortedList like strApproved = slList.Item("approved").  But how do I load the SortedList without doing something clunky with the InStr and Substring methods?

Dim strArray() = strValues.Split("&")

For Each strValue As String In strArray

If InStr(strValue, "approved") Then

strApproved = strValue.Substring(9, 1)

ElseIf InStr(strValue, "funded") Then

strFunded = strValue.Substring(7, 1)

ElseIf InStr(strValue, "winprob") Then

strWinProb = strValue.Substring(8, 1)

End If

Next

 

Thanks for the help.

 Kent

0
kent
1/23/2008 9:55:24 PM

Hi

Perhaps you can try the following code snippet to retrieve the values from the string above.

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        Dim strValues As String = "&approved=1&funded=0&winprob=2"
        Dim strWinProb As String
        Dim strApproved As String
        Dim strFunded As String
        Dim strArray() = strValues.Split("&")
       
        For Each str1 As String In strArray
            If str1 Is Nothing Or str1 = "" Then
                Continue For
            Else
                Dim substrarray() = str1.Split("=")
                Select Case substrarray(0)
                    Case "approved"
                        strApproved = substrarray(1)
                    Case "funded"
                        strFunded = substrarray(1)
                    Case "winprob"
                        strWinProb = substrarray(1)
                End Select
                       
                       
            End If
        Next
    End Sub

Regards,

Xun


Regards,
Xun Ye.
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that
helps you, and to click “Unmark as Answer” if a marked post
does not actually answer your question. This can be beneficial
to other community members reading the thread.
0
Xun
1/25/2008 6:25:58 AM
Reply:

Similar Artilces:

How to Access/Pass Server Side Array Variable at Another Web Form's Client Side
Hi All,I struck up with some intrested senario at my application development...hope some body will guide me or sends me some code snippets....Thanks in advance.Senario is like this.....in A.aspx (using C# .net 2.0 as code behind) I am going to have a array variable basically it is an TWO Dimensional array after populating the values in array I need to redirect/ reload another web form B.aspx, here i need to access the array in B.aspx client side JavaScript.How can I do this...Thanks AgainRaju Dont do a redirect but use server.transfer. That way the previous page will still hold its value, ...

Passing random array data from server-side to client-side
Hi,   I have encountered a problem with the following codes. I want to display the list of results (random arrays) in a textbox or label. But however, it cannot displayed the 3 random values at one time, instead it can only displayed one value at a time. When I tested out using reponse.write, there is no such error. I want to do this because I want to pass the array data from server side to the client side for other purpose. Can someone please help?? Thanks!Dim dataX(3) As Double Dim dataY(3) As Double For i As Integer = 0 To 2 Randomize() dataX(i) = Int((Rnd() * 25) + 1) da...

Passing client side to server side using hidden field
 I have a hidden asp.net text box that is being updated on the client via javascript. I am trying to determine the best way to detect when that hidden field has changed and read the new value on the server. I would like to do this WITHOUT posting back. I have tried using the TextChanged event but that requires blur state to be changed before it gets fired. What would be the best way to do this? Thanks, Justin.  Can you use __doPostBack() to trigger a partial postback at the same time the hidden TextBox is updated, from JavaScript? Encosia - ASP.NET, AJAX, and more.Lates...

sending data from client side to server side without postback?
Hey guys, Im having a little bit of trouble to get this working in my page, i have some javascript in my page which displays rows selected from a dropdown list. asp dropdown just errors when i try to use selectedindexchanged and when i add runat="server" to the <select> the javascript doesnt fire off. so im trying to make the javascript store this value into something where its accessible by my backend code and my C# can pick it up (like a hidden text input or something), but at the moment it isnt working :(Code: <script type="text/javascript">function Sh...

value(Byte Array) send from server side(.aspx) to client side(vbscript).
Hi, I am facing some problem in retrieval of value(Byte Array) from server side(.aspx) to client side(vbscript). I am using the code at button click eventprivate void Button2_Click(object sender, System.EventArgs e) { System.Drawing.Image objImage = System.Drawing.Image.FromFile("C:/2.gif");MemoryStream objMemoryStream = new MemoryStream();   objImage.Save(objMemoryStream,System.Drawing.Imaging.ImageFormat.Gif); objByte = objMemoryStream.GetBuffer(); txtByteArr.Value = Convert.ToString(objByte); } where txtByteArr is the input hidden field and runat server.  ...

How to send array of objects from client to server side web service ???
Is this possible ? ----------- client side ------------------- var test = new Array(); test[0]="test1"; test[1]="test2"; var test1 = new Array(); test1[0]="test122"; test1[1]="test222"; var arr= new Array(); arr[0]=test; arr[1]=test1; page.getedit(pero); ------------------ server side ---------------------- <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)> _ Public Function getedit(ByVal conArr() As Array) As String   Return "ok" End Function Thanks ! Igor I see that you have an AjaxMethod attribute on your method, which is not what Atlas uses.&n...

SERVER SIDE DATA VALIDATION ON CLIENT SIDE
I wonder if this is the right forum to post this question because it is an issue about both server and client side processing. I am developing a web application (online store) which will run in a hosting company. Users accessing this app will be able to place orders with one limitation; the store has a schedule to accept orders. For example, it can be open from 8AM to 10PM and/or it can be closed on Mondays. I just can't validate time and/or day directly because time zone may lead to wrong results. So I thought about getting the schedule information, which is saved in my database, ...

How to pass server side array to client side
Hello Friends.....   i want an intelligent textbox.....which pop up a list of data when any character is pressed in perticular textbox.......... the data should be related fields which are stored in database .........   for that i am having a javascript...........but it is static .....it has a static array and generates output..... but i want that particular with my own datafields.......   so please any one help me...... i will be very thank full........   Thanx and regards sandeep prajapatiBhaaratRemember to click "Mark as Answer" on the post t...

differences between server side asynchronous Web methods and client side asynchronous Web methods
Hi,   can anyone expalin what are the differences between server side asynchronous Web methods  and client side asynchronous Web methods in ASP.Net 2.0 ?   any best articles on serverside asynchronous Web methods  ?   Thanks,  hi, check this url, Server-Side Asynchronous Methods for ASP.NET, http://www.codeproject.com/KB/cpp/asyncws.aspx   Calling the Server-Side method asynchronously from Client Script, http://www.c-sharpcorner.com/UploadFile/dipenlama22/Callbacks07182006093320AM/Callbacks.aspx...

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 (Asp.net) 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...

Data format in TextBox in both Server side and Client side?
HI,      I have a GridView which shows data in TextBox.      I was wondering if there is a way to do data format (Currency) like $12,203.00. I need it working in server side (for existing data) and client side (for new data or changed data). What I mean about client side is data automatically formatted after data is keyed in.     Thanks for your help. Hi you can use MaskEdit in AjaxControlToolkit please check here http://www.asp.net/AJAX/AjaxControlToolkit/Samples/MaskedEdit/MaskedEdit.aspx this is a cool control. Hope it...

Passing list or array from server side to client side
I need to pass an array or two from my server side code to my client so that I can use that info with the Java script event handlers.  Is this possible and if so how?The reason I 'think' I need to do this is because I need to fill in a text field upon a change in my list box without reposting because the load event requires database access.  I'm rather new to asp so I might not be going about this in quite the right way.   Thanks.  You should really take a look at the AJAX toolkit, (see http://ajax.asp.net) because this will let you do exactly what you need.Regards...

pass array object from client side to server side
dear all, i need to pass objects from client side javascript to server side  is there any way to do that..  i have tried hidden field but we can't assign array objects to the hidden fields is there any other way to store array object in server  URGENT!!! Thanks. raj  URGENT, I waited to the last minute to get HELP! I am screwed! No one cares it is urgent!You need to convert it to a string. If it is an Array, use the join() method and store it to a hidden field.  Eric Pascarello.com | Twitter epascarello | LinkedIn LOL, ...

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

Web resources about - Sending array data with hidden input field from client side to server side - asp.net.web-forms

Sending/receiving relationship - Wikipedia, the free encyclopedia
A sending/receiving relationship is one in which a public school district sends some or all of its students to attend the schools of another ...

U.K. Woman Faces 20 Months For Creating Fake Facebook Accounts, Sending Herself Abusive Messages
A woman in Cornwall in the U.K. came up with a creative way to use Facebook to accelerate a family spat, and it earned her 20 months in prison. ...

CHVRCHES - Dear guys, Please stop sending us emails like... - Facebook
Dear guys, Please stop sending us emails like this. This is one of the more polite ones. Other recent classics include "I'm going to give her ...

Facebook Sending Perez Hilton More Traffic than Google, Driving 3.3% of All US Traffic to Video Sites ...
For media companies evaluating their Facebook marketing strategy , here’s an interesting sign of the times: web analytics firm Hitwise is reporting ...

A better experience for sending Tweets and DMs - Twitter Blog
... panel New Tweet panel in da...... Skip to main content Blog Got an account? Sign in Search form Search &nbsp A better experience for sending ...

How to Go From Working 60 Hours a Week to 40 By Sending 2 Emails a Week
I’m convinced 95% of cubicle workers who work over 60 hours a week constantly can cut it down to 40-45 hours by sending 2 emails a week to their ...

Live Emoji - sending GIF Animation Emoji for Zoosk,Skype,Kik,Whatsapp,Facebook Messenger Etc. on the ...
Get Live Emoji - sending GIF Animation Emoji for Zoosk,Skype,Kik,Whatsapp,Facebook Messenger Etc. on the App Store. See screenshots and ratings, ...


Cynthia McKinney - responds to Obama on sending troops into Afghanistan - Debate Answer - YouTube
Cynthia McKinney, Green Party Presidential candidate, responds to Barack Obama on his support for sending troops into Afghanistan. Based on his ...

Great-grandmother 'would die' before sending kids to Italy
Great-grandmother 'would die' before sending kids to Italy

Resources last updated: 12/14/2015 12:59:08 AM