ASP.NET partial page upload without Updatepanel /With jQuery

后端 未结 4 2019
孤街浪徒
孤街浪徒 2021-01-07 13:33

I have an ASPX page .In the Top i am displaying 5 categories (Ex : Pen,Book,Shoe,Mobile,Mirror) When i click on any of the categories,I want to show the products under that

4条回答
  •  半阙折子戏
    2021-01-07 14:30

    According to me, using an UpdatePanel wrapped around a Repeater/DataGrid/GridView will be a much more easier-to-implement approach.

    It can also be done with jQuery. It would consist of sending the CateogryId using an ajax request to the server, getting the products' JSON in response, and filling up a div with the JSON data using DOM manipulation.

    EDIT: Using JSON, complex data can be represented in an easy to read text format, in an object oriented way. Take a look at this -

    var person = {
         "firstName": "John",
         "lastName": "Smith",
         "address": {
             "streetAddress": "21 2nd Street",
             "city": "New York",
             "state": "NY",
             "postalCode": 10021
         },
         "phoneNumbers": [
             "212 555-1234",
             "646 555-4567"
         ]
     };
    

    person is a JSON object consisting of the following properties: "firstName", "lastName", etc. You can access these properties using person.firstName, person.lastName,etc.

    This is an example of JSON, you can utilize this to create your own JSON string containing product information and send it in an array to the client. In short, it will be an array of objects like this -

    var persons = [person1, person2, person3, ...]; //person1, person2, etc. are objects like the person object declared above.
    

    You can use the DataContractJsonSerializer class (in Framework 3.5) to serialize/deserialize object to and from JSON. If you are using Framework < 3.5, you can use the JavaScriptSerializer class of AjaxToolKit to do the same.

提交回复
热议问题