Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9040905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:06:23+00:00 2026-06-16T10:06:23+00:00

i’d like to better understand the issue of casting object to a name vs

  • 0

i’d like to better understand the issue of casting object to a name vs value collection

say …just if i could do it like that

1) does the java-script needs some fine tuning ? packing the data..

2) and most important for me : What is the correct way to do the conversion from that key value Js to a Dictionary<T,T> C# ?

the Aspx / Html part

<input type="text" id="tbx_Name" value="Avi" />
<input type="text" id="tbx_City" value="TelAviv" />
<input type="text" id="tbx_Country" value="Israel" />

<select id="ChosenRandomClass" style="display:none">
<option selected="selected" value="0">(choose a random)</option>
<option value="1">random Top Beach</option>
<option value="2">random Top Center</option>
<option value="3">random Local Pub</option>
</select>

the JavaScript / jQuery part

  function AddNew() {

        if (!confirm("would you like to add this contact ?")) return;

        var Name = $('#tbx_Name').val();
        var City = $('#tbx_City').val();
        var Country = $('#tbx_Country').val();

        var selectedRC = $('#ChosenRandomClass option:selected').val();

        var hDate = []

        var param1 = { key: "Name", value: Name };
        var param2 = { key: "City", value: City };
        var param3 = { key: "Country", value: Country };
        var param4 = { key: "SelctedClass", value: selectedRC };

        hDate.push(param1);
        hDate.push(param2);
        hDate.push(param3);
        hDate.push(param4);
                                         // is this part necessary the data will not get to
                                         // code behind properly without the serializing ?
        var startPrt = Sys.Serialization.JavaScriptSerializer.serialize(hDate);
              ajaxUpdate("addNew", startPrt);

    }

the Code behind C# part

public void AddNewRecord(object startPrt)
{
    Dictionary<string, string> SenthDate = new Dictionary<string, string>();
   //        .....etc

}

i will appreciate the correct answer

thanks for your kind help and time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:06:24+00:00Added an answer on June 16, 2026 at 10:06 am

    I gave your sample a try and noticed that the startPrt parameter is actually being received as an Array of Dictionary(string, object). Hence, if you make the AJAX call like this:

    var hDate = [];
    hDate.push({ key: "Name", value: Name });
    hDate.push({ key: "City", value: City });
    hDate.push({ key: "Country", value: Country });
    hDate.push({ key: "SelctedClass", value: selectedRC });
    
    $.ajax({
        contentType: 'application/json; charset=utf-8',
        url: 'MyPage.aspx/AddNewRecord',
        type: 'POST',
        data: JSON.stringify({ startPrt: hDate }),
        success: success, // success callback
        error: error // error callback
    });
    

    You can define your WebMethod like the follwoing to convert the startPrt parameter to a dictionary:

    [WebMethod]
    public static void AddNewRecord(object startPrt)
    {
        var dict = new Dictionary<string, object>();
        foreach (Dictionary<string, object> pair in (Array)startPrt)
            dict.Add((string)pair["key"], pair["value"]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.