I want to send Java script Array values to C# code behind file
I have Check Boxes in Dev Express gridview and and now on client click event I want to
take selected check box values in java script array. and then on button click I want
to send that values to code behind using json ajax call.
But It is giving Error Message.
What I have tried:
ASPX Code For Gridview With Check Box
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="AccId"
ClientInstanceName="grid">
<Columns>
<dx:GridViewCommandColumn ShowSelectCheckbox="true"></dx:GridViewCommandColumn>
<%-- <dx:GridViewDataTextColumn>
<DataItemTemplate>
<dx:ASPxCheckBox ID="cbCheck" runat="server" Visible="true" AutoPostBack="true"></dx:ASPxCheckBox>
</DataItemTemplate>
</dx:GridViewDataTextColumn>--%>
<dx:GridViewDataTextColumn FieldName="AccId" ReadOnly="True" VisibleIndex="1">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="AccessName" VisibleIndex="0">
</dx:GridViewDataTextColumn>
</Columns>
<ClientSideEvents SelectionChanged="grid_SelectionChanged" />
</dx:ASPxGridView>
Then Bellow this button control as
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DemoDBConnectionString %>"
SelectCommand="GetUserAccess" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<input id="Button1" type="button" value="GetData" onclick="myfun()" />
Java Script Function in Head Section as follows
<script type="text/JavaScript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
var myval = [];
function grid_SelectionChanged(s, e) {
alert("Click");
s.GetSelectedFieldValues("AccId", GetSelectedFieldValuesCallback);
}
function GetSelectedFieldValuesCallback(values) {
alert(values);
try {
myval.push(values);
}
finally { }
}
function myfun() {
$.ajax({
type: "POST",
url: "WebForm1.aspx/MyMethod",
contentType: "application/json; charset=utf-8",
data: "{ Param1: '" + myval + "'}",
dataType: "json",
success: function (result) {
alert('Yay! It worked!');
},
error: function (result) {
alert('Oh no :(');
}
});
}
</script>
code behind file Method(.cs files) as
[WebMethod]
public static void MyMethod(string []Param1)
{
try
{
}
catch (Exception)
{
throw;
}
}
but it is giving Error as
Oh no
plese help me to solve this
Thanks in advance