Parse JQuery Serialized Data In C#?

Oct 13, 2010

I have a ListBox on my page. I'm making an AJAX call to a C# function, and I need to pass the values of the selected items. Here's what I have:

$('#btnSubmit').click(function() {
$.ajax({
type: "POST",
url: 'Default.aspx/GetSelectedValues',
data: '{selectedValues: ' + $('#lbItems').serialize() + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess
});
});
<select id="lbItems" multiple="multiple">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>
[System.Web.Services.WebMethod]
public static string GetSelectedValues(string selectedValues)
{
//
}

The data being passed to the C# function looks like:

lbItems=1&lbItems=3&lbItems=5

Is there any built-in C# function that can deserialize that easily, to convert the values into an array of some sort? Or maybe there's a better way to pass the data from jQuery?

View 3 Replies


Similar Messages:

C# - Passing JSON Serialized Data Via Hidden Field?

Mar 2, 2011

In ASP.NET WebForms I want to pass arbitrary data from server to client and back again. I am serializing to JSON and have been simply producing JavaScript that creates the object on the client. I have no problem sending data to the server with ajax, but there are situations where I also want to send a Javascript object data back to the server on postbacks. So I guess it needs to be in a hidden field.

1) What is the best way to do this in terms of minimizing complexity and optimizing space and efficiency? In researching this I discovered Protocol Buffers but there does not seem to be a good C# implementation. I did find one, but it was a couple years old and self-described as buggy so that scared me.

2) If I just pass a JSON string, how can I be sure it will be safe to include as the value for a hidden field? Is there any reason I might not want to do this? I could Base64 encode, but it seems like this adds a lot of overhead. What is considered the best or preferred method?

View 1 Replies

Jquery - Json.net Web Service - How To Return And Parse Dates

Aug 10, 2010

After much head scratching as to why my returned Json string is breaking JSON.parse, I have realized that it is the returned dates that it doesn't like.

.net property:-

[code]....

View 2 Replies

JQuery :: Parse Or Use Returning A String Array From Websevice?

Dec 27, 2010

i wrote a webservice method. i am using it with ajax jquery. method returns string[] array. ho can i read array's values using ajax jquery.

View 3 Replies

C# - Deserializing An Object That Is Different Than When It Was Serialized?

Mar 29, 2011

I have an issue with deserializing an object. I get an error 'System.Int32' cannot be converted to type 'System.Decimal'. This object has many child objects and since this object has been serialized, a new version of the object has one or many fields that have been changed from int to decimal and now I can't deserialize the object because it doesn't match my original object.

I have tried using the OnDeserializing method but the context parameter.

Is there a way around this? I've found some examples online but it doesn't really apply to my situation. I would just like to know if there is a way to view my serialized object even if my object has now changed or if there is a way to find out which variable needs to be changed to decimal and how to go about doing it.

I've added your code but I'm not quite sure how to call it from my code. Here's what I've got:

public static Application LoadSnapshot(int appID, int statusID)
{
ApplicationSnapshotCollection AppSnap = new ApplicationSnapshotCollection();
AppSnap.LoadByAppAndSnapshotStatusID(appID, statusID);

[Code]....

How do I go about calling the constructor with the proper parameters in my scenario?

View 1 Replies

Serialized Objects In View State?

Mar 10, 2011

i have been going through the documentation of viewstate. [URL]It was mentioned that objects that can be serialized are stored in viewstate. What is the meaning of serializing of objects ??

View 2 Replies

SQL Server :: Deserializing Object That Is Different Than When It Was Serialized

Mar 29, 2011

I have an issue with deserializing an object. I get an error 'System.Int32' cannot be converted to type 'System.Decimal'. This object has many child objects and since this object has been serialized, a new version of the object has one or many fields that have been changed to decimal and now I can't open or view the object because it doesn't match my original object. Is there a way around this? I've found some examples online but it doesn't really apply to my situation. I would post some code but I don't think it would really help...I would just like to know if there is a way to view my serialized object even if my object has now changed and how to go about doing it.

View 2 Replies

Best Way To Determine Type Of Object Serialized To XML?

Jan 2, 2011

I have a table in my SQL Server DB that holds auditing information for certain actions a user takes within my system. Things like who performed the action, when it was performed, and what action are all pieces of information that can easily span multiple actions. But depending on the action performed, there may be other information that I want to capture, that is specific to the action. To handle this, I elected to add an "XML Metadata" column to the table that holds serialized XML of different metadata objects that I've created. I created a metadata object for each of the actions that I'm interested in tracking extra for. So each object is responsible for tracking specific extra information (metadata) for it's action. The objects are serialized and written to my new column.

I have SystemAction objects that I use to store information from this table, and I've added a string field that holds the XML string from the DB. The problem is, when I'm reading this XML back from the SystemAction objects, I'm struggling with a way to generically translate it back into it's correct metadata object. Each metadata object is going to have different fields, and each object has it's own static method that takes an XML string and attempts to return the metadata object type. So I could say:

SomeActionMetadata mdObj = SomeActionMetadata.BuildFromXML(xmlStringFromDB);

But I really don't know of a way to say "Here's some XML that could translate to any number of different objects. Figure it out and give me the right object back."

Given my current implementation, I could always just assign a unique ID to each metadata object that is stored as a field in each object, then use a case statement to switch on that ID and use the appropriate class's static build method to build the right object. But I was hoping for something a little more automatic than that. What if I have a List of SystemAction objects and just want to loop through them and generate the correct metadata object type?

View 1 Replies

WCF / ASMX :: Linq To SQL Web Service Cannot Be Serialized?

Feb 6, 2010

I'm playing around with Web Services using Linq to SQl. I apparently have a lot of learning to do. What I'm trying to do below is pull data from the Northwind db Employee Table. I don't need to see the whole table, I'm just trying to select individual(s) but I keep getting the following error

"System.Data.Linq.Binary cannot be serialized because it does not have a parameterless constructor"

Code Below:

<WebMethod()> _
Public
Function EmployeeInfo()
As List(Of Employee)
Dim db
As
New NorthwindDataContext()
Dim output =
From cust
In db.Employees _
Select cust.EmployeeID, cust.FirstName, cust.LastName
Return output
End
Function

View 7 Replies

Write Serialized XML To String And Display In Browser?

Aug 1, 2010

I have a serialized object which needs to be sent as an encrypted XML string. I am able to save the serialized object to a well-formed XML file, but this is not what I want. I have already got Rijndael encrypt/decrypt working for a sample string.

Person person = new Person("Irish", "Chieftain");
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Person));
// Write serialized XML to file
System.Guid guid = System.Guid.NewGuid();

[Code]....

View 1 Replies

How To Parse Html And Get Specific Data

May 2, 2010

i have an html (save in a string variable if needed) and i want to use the content of one of the html's tables (the html page has 4 tables an i want only one of them) . i read a lot of similar post but i didn't find anything helpful. on how to parse the html and get the content of one of the tables so i can use this data later?

View 5 Replies

Data Controls :: Parse JSON Data From URL And Display In GridView

May 7, 2015

How to parse [URL].....

I am referring below link of urs : How to read JSON string into DataTable and Class object using C# .Net 

my code to get data into string :

        Dim data As String = New System.Net.WebClient().DownloadString("[URL]") 

now i want it to get into data table , so that i can bind it with grid later on.

 JSON String

{"
record":
[{"id":"0",
"Date":"11/14/2014",
"Time":"12:00AM",
"programme":"Stops Here",
"synopsis":"A show that brings you the big interviews",

[Code]......

View 1 Replies

Can Use SSIS To Parse Data From Application Before Store In Db

Mar 29, 2011

Exploring the feasibility of something here... We have a UI page in the mvc3 web-application that the admin will use to upload a 'csv' file. Is it possible to have an SSIS package that will be called by the application..that will validate/transform all these data and store into db if its all valid or throw back error details to application if there are invalid data?

Just trying to leverage the capabilities of SSIS to do the parsing of file and transformation of data. If this is not possible, is there a better way?

update: yes, need to execute ssis on the fly.. and give back a message on the UI page. telling the'uploader' if his upload failed or not based on message that SSIS would give back to the application.

View 4 Replies

VS 2010 - How To Parse Excel Files Data In WebForms Using C#

Nov 14, 2010

how to parse excel files data in ASP.NET WebForms using C# or ASP.NET MVC using C#?

View 8 Replies

C# - How To Parse Html File To Follow Up Specific Data

Oct 2, 2010

My target web site is: [URL]

focus this on that page: "XU100 64.882,72 -1.36 %" it is on top..

The exact target is 64.882,72 this value!...

What is the best way for this value?

My platform: asp.net , c#

View 1 Replies

Forms Data Controls :: Gridview Check Box And Parse()?

Oct 5, 2010

Documentation for using a checkbox with a gridview has the following statement:Because a check box can display only a selected or an unselected state, a CheckBoxField object can be bound only to a field with a Boolean data type or a string that can be parsed byParse.No example has yet been found to explain how using Parse to control the value of theis done. Interestingly enough I can find a fine example for the unlikely scenario of embedding a bulleted list in a grid cell.

View 4 Replies

Forms Data Controls :: Fail To Parse Variable To A Link Button?

Feb 14, 2011

I want to create a link button with following code. However, this linkbutton doesnt work correctly: when I clicked it, it cannot go to the target url and will cause an exception.

<asp:LinkButton PostBackUrl='LearnPage.aspx?cid=<%#Eval("cid") %>' runat="server"><%# Eval("cname")%></asp:LinkButton>

(The linkbutton is one column of a grid view)

Debugging the code, I found that the value of cid is not parsed to the url. Actually, this code <%#Eval("cid") %> is not recognized as a variable, the target url appears to be LearnPage.aspx?cid=<%# Eval("cid") %> instead of LearnPage.aspx?cid=VALUE.

View 1 Replies

"The EntityReference Object Could Not Be Serialized" When Serializing From .NET Web Site,?

Mar 22, 2010

I have an Entity Framework data model. Part of the model is a Customer entity. The web service provides a method to get a customer, and to receive an updated version of this customer to be persisted.

To test this, I created a new ASP.NET web Application, (Solution > Add > New Project > ASP.NET Web Application), then added a reference to my service reference using the standard Add Service Reference dialog. I then call the service using the following code:

var client = new CustomerServiceClient();
var customer = client.GetCustomerByID(18); // get it
customer.LimitDown = 100; // change it
client.SaveCustomer(customer); // persist it


Everything works as expected.

Now, I do exactly the same thing, but this time with as ASP.NET Web Site (Solution > Add > New Web Site > ASP.NET Web Site). I add the reference in a similar fashion and copy and paste the code above into the new site. But now I get the following exception thrown on the 4th line:

System.InvalidOperationException The EntityReference object could not be serialized. This type of object cannot be serialized when t RelationshipManager belongs to an entity object that does not implement IEntityWithRelationships.

Source Error:

Line 2474: Line 2475:
public
SkyWalkerCustomerService.OperationResult
SaveCustomer(SkyWalkerCustomerService.Customer[code]....

Googling for this error returns very little. Why doesn't this work?I guess one answer would be to use a web application instead of a web site, but I have an large existing site to which I need to add the service reference, and I'd rather not convert it.

View 1 Replies

How To Parse A Csv File

Jun 30, 2010

we are trying to use google to get exchange rate prices.

they use a csv file which we get the code to go out and get.

what im trying to do is pick the first line of the file and just use that. i have the following code but its not just picking the one line.

[code]....

View 3 Replies

How To Parse Text At A URI

May 23, 2010

I can use the TextFieldParser Class to parse the text of a file in the file system (given the abslolute path) but it won't parse text from a file whose location is identified by a URI.

View 8 Replies

Parse HTML With PHP?

Jan 27, 2010

The question is not really about parsing the HTML, but rather parsing the HTML and adding elements to the DOM according to the HTML tags. For example - I want to be able to take an HTML page, add attribute to the HTML tags - such as "class='replace'", put some PHP/ASPNET code in the page (make an ASPX page with ASPNET or put some include with PHP) and make them parse the page every time it is accessed and manipulate the DOM of the tags marked as 'class="replace".

For example if I have < div class='replace'>< /div>, after I run the script I'll get something like < div class='replace'>This is a new text< /div>

View 2 Replies

C# Parse Int As Datetime?

Oct 6, 2010

Given a time: 1286294501433Which represents milliseconds passed since 1970, how do we convert this to a DateTime data type? EG:

transactionTime = "1286294501433";
UInt64 intTransTime = UInt64.Parse(transactionTime);
DateTime transactionActualDate = DateTime.Parse(intTransTime.ToString());

Throws: String was not recognized as a valid DateTime.Please note all times passed into this function are guaranteed to be after 1970.

View 2 Replies

Parse A Page On The Web?

Dec 16, 2010

Where I live the local transport service has this page where you can read about delays and disturbances in the traffic. I would like to parse this page so I can store this data and make a nice report of it.

The problem is that to be able to get the information you need to submit a form by making some choices and clicking a button. You can't just visit the page.

How can I get the information "behind" the form from code so that I can parse it?

View 5 Replies

Parse The HTMLDocument In C#?

Jul 22, 2010

I want to get the text of an html page using a simple application in c#?If there are nested elementsie.,

<Table>
<TR>
<TD>**ABC**

[code]...

View 1 Replies

C#: Parse UserAgent Into HttpCapabilitiesBase?

Jan 5, 2011

Is there anyway to parse an useragent string into an HttpCapabilitiesBase object? (this is what you get from (HttpRequest)request.Browser).

If not is there any other good way to parse useragent string in .NET.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved