Click here to Skip to main content
15,567,221 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to call array type methode from jquery so below code is working fine.

XML
<script type="text/javascript">
        $(document).ready(function () {
            $("#tblCustomers tbody tr").remove();
            $.ajax({
                type: "POST",
                url: "GetDataByJquery.aspx/GetMessages",
                data: '{roomId: "' + $("#lblRoomId").val() + '" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    response($.map(data.d, function (item) {
                        var rows = "<tr>"
                    + "<td class='customertd'>" + item.Username + "</td>"
                    + "<td class='customertd'>" + item.Sex + "</td>"
                    + "<td class='customertd'>" + item.Text + "</td>"
                    + "<td class='customertd'>" + item.TimeStamp + "</td>"
                    + "<td class='customertd'>" + item.UserID + "</td>"
                    + "</tr>";
                        $('#tblCustomers tbody').append(rows);
                    }))
                },
                failure: function (response) {
                    alert(response.d);
                }
            });
        });
    </script>



so in this I cant get label control value to pass below webmthode.

[WebMethod]
        public static Messages[] GetMessages(string roomId)
        {
            List<Messages> messages = new List<Messages>();           
            string strConnString = ConfigurationManager.ConnectionStrings["LinqChatConnectionString"].ConnectionString;

            using (SqlConnection con = new SqlConnection(strConnString))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter())
                {
                    string query = "[Get_Messages]";
                    SqlCommand cmd = new SqlCommand(query);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@roomId", roomId);
                    cmd.Connection = con;
                    sda.SelectCommand = cmd;
                    con.Open();
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Messages message = new Messages();
                        message.Username = reader.GetString(0);
                        message.Sex = reader.GetString(1);
                        message.Text = reader.GetString(2);
                        message.TimeStamp = reader.GetString(3);
                        message.UserID = reader.GetString(4);
                        messages.Add(message);
                    }
                }
            }
            return messages.ToArray();
        }


So how to pass asp.net label control value to 'GetMessages' methode's parameter?
Posted

1 solution

USE HIDDIN FIELDS TO STORE VALUE OF LABEL AND USE HIDDENFIELD VALUE
 
Share this answer
 
Comments
Dawood507 26-Aug-15 3:37am    
can you show one example plz..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900