C# - Returning Multiple Values To Be Used In JQuery From A WebMethod
Mar 3, 2011
I have jquery using ajax/json to grab an elements ID and then hits:
[System.Web.Services.WebMethod]
public static string EditPage(string nodeID)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(Global.conString))
using (SqlCommand cmd = new SqlCommand("contentPageGetDetail", con))
{
cmd.Parameters.Add("@ID", SqlDbType.UniqueIdentifier).Value = Global.SafeSqlLiteral(nodeID, 1);
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
if (dt.Count > 0)
{
string pageTitle = dt.Rows[0]["Title"].toString();
string contentID = dt.Rows[0]["ContentID"].toString();
return pageTitle, contentID, nodeID;
}
else
{
return "Failed";
}
}
When it's time to return I want to grab all content returned from the stored procedure back to the jquery method in the success section and set a hiddenfield, dropdown value, and a title in a textfield. In the jQuery I tried using "pageTitle" but it came up undefined. What do I need to do jQuery side to grab whats being returned and populate fields in my Web Form before showing the form?
View 3 Replies
Similar Messages:
May 7, 2015
i want to return multiple(name and statusid) parameter from web method and want to retrive in javascript function how to use it.Â
I have attached my code.Â
[System.Web.Services.WebMethod]
public static string CheckPromotionCode(Int32 id)
{
string name="kausha";
string statusId = "6";
[CODE]...
View 1 Replies
Nov 27, 2010
My Problem is that i am returning a json string from a webmethod from an aspx page.
I want to create a dynamic html table using that json string but found no solution for that.
Can anyone Provide me the solution to generate html table from json string ?
View 6 Replies
Mar 8, 2011
public class JsonBuilder
{
private StringBuilder json;
public JsonBuilder()
{
json = new StringBuilder();
}
public JsonBuilder AddObjectType(string className)
{
json.Append(""" + className + "": {");
return this;
}
public JsonBuilder Add(string key, string val)
{
json.AppendFormat(""{0}":"{1}",", key, val);
return this;
}
public JsonBuilder Add(string key, int val)
{
json.AppendFormat(""{0}":{1},", key, val);
return this;
}
public string Serialize()
{
return json.ToString().TrimEnd(new char[] { ',' }) + "}";
}
}
Here is the Web Method [WebMethod]
public static string GetPersonInfo(string pFirstName, string pLastName)
{
var json = new JsonBuilder().AddObjectType("Person");
json.Add("FirstName", "Psuedo" + pFirstName).Add("LastName", "Tally-" + pLastName);
json.Add("Address", "5035 Macleay Rd SE").Add("City", "Salem");
json.Add("State", "Oregon").Add("ZipCode", "97317").Add("Age", 99);
return json.Serialize();
}................
View 1 Replies
May 19, 2010
I have a service that works great on my development box. It uses JQuery to hit my web service, and then the JSON results are sent back.
The web service is located on our basePage.cs. We didn't want to put out an external WebService for this. Our on beta box something different is happening.
The web page seems to be trying to call the web method correctly - the JSON data is being sent... but the server doesn't seem to know it's a webmethod. here's my service function (it's in our basepage.cs which inherits from Page).
[Code]....
View 2 Replies
Feb 8, 2011
I'm designing a page which makes an ajax call (via jQuery.ajax) to a page method on the server side.On the server side, I have two classes: Agent and Channel.
In the page method, I'd like to return a List<Agent> and a List<Channel> to the client side. How can I return two lists to client side? should wrap them up in one class like:
[code]....
View 4 Replies
Sep 16, 2010
I have a simple web method written in the code-behind (not a separate asmx) of a test aspx page.
All it does is return a DataTable(or DataSet) both are failing, gives a blank 500 error saying "There was an error processing the request"
If I switch the return variable type to String, it works fine
I think my issue has to do with the version of the System.Web.Extensions, is that the assembly that actually contains the JSON communication implementation?
I've read all kinds of tutorials about how it should be possible to return the DataTable to javascript and then read the properties with javascript syntax.
For some reason it isn't working for me.
My web extensions is imported through my web.config with the following version
<add
assembly="System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
View 5 Replies
Feb 3, 2010
Below is the jquery script that takes one input value from textBox1 and pass it to a web method then returns the name of the person and displays it in textBox2. The web method only takes one parameter, the user initials.
[code]....
I want to be able to pass two values from two textboxes for a web method that requires two parameters. how can I modify the jquery code above to accomplish that?
View 4 Replies
May 7, 2015
(function () {
var linechartResize;
linechartResize = function () {
$("#linechart-2").sparkline([160, 240, 250, 280, 300, 250, 230, 200, 280, 380, 400, 360, 300, 220, 200, 150, 100, 100, 180, 180, 200, 160, 220, 140], {
type: "line",
width: "100%",
height: "226",
[Code] ....
In the above javaScript function i am supplying numeric array . I want those values from C# method which gets the those values from database....
View 1 Replies
Mar 16, 2010
How do I run a webmethod with jQuery. Asp.Net
the method load it the GridView
[WebMethod]
public void GetGrid()
{
DataProviderDataContext db = new DataProviderDataContext();
GridView1.DataSource = db.Employees.ToList();
GridView1.DataBind();
[code]...
View 1 Replies
Jan 24, 2010
How to return values from Webmethod to the client in JSON format? There are two static int values that i want to return.Do I need to create new object with those 2 properties and return it?The GetStatus() method is called frequently and i don't like the idea of creating a special object each time just for json formatting...
[WebMethod]
public static int GetStatus()
{
int statusProcess,statusProcessTotal;
Status.Lock.EnterReadLock();
statusProcess=Status.Process; //Static field
statusProcessTotal=Status.ProcessTotal; //Static field
Status.Lock.ExitReadLock();
return ...
}
On client side I catch the return value in :
function OnSucceeded(result, userContext, methodName)
(PageMethods.GetStatus(OnSucceeded, OnFailed);)
View 1 Replies
Nov 8, 2010
I cannot call webmethod from jquery. I think its about web.config file. How can i set web.config file for web services and webmethod?
View 1 Replies
Sep 28, 2010
Upon clicking a button I need to send a collection and a few other variables to server in Json form.For each value in the collection the server code (C# ) wil update those other variables in the DB.
For example there is a ‘classnumber’ collection with values (First, Second, Third, ….),other variables (‘teacher_name’ and ‘subjectname’).For each value in the ‘classnumber’ collection I need to update the ‘teacher_name’ by searching for the ‘subject_name’ in the DB.So I need to pass the ‘classnumber’ collection,’teacher_name’,’subject_name’ values to server in json form. At the moment instead of sending the ‘classnumber’ collection I am sending ‘teacher_name’,’subject_name’,’classnumber’ as variables for each value in the collection ,which requires multiple requests made to the server.
Instead of these individual requests I am wondering if there is a way to send all the data at once to server in json form?
View 1 Replies
Apr 5, 2010
I am developing a user control. This user control is having 2 Dropdown controls and one textbox('txtCustomer'). I am using autocompleteextender for the text box. This 'txtCustomer' control populates the data based on the value selected in 2 dropdowns.
I need to pass the selected value of this 2 dropdown to my meb method. I am not using web service(.asmx page) for this application instead i am using page level web method. I tried to access the controls from the web method inside the Page. but all the identifiers and controls of the page returning null in the web mothod. I have analysed it is because the events "page_Load and page_Init" are not getting fired.
View 6 Replies
Jun 16, 2010
Is there a way to retrieving parameter names and values passed to a web method from Request object? I've read somewhere that you need extra code to access the soap body. Any known workarounds to be able to see the soap body from Application_BeginRequest?
View 1 Replies
Mar 26, 2011
I am using a webform and trying to use a $.ajax call a webmethod on my code behind to format and return some data. It sounded easy but I need the help of an expert. Here is what I have and perhaps someone could steer me in the right direction to solving this problem. for the time being all I want the [webmethod] to return is some dummy data so the jqgrid displays, after I get it displaying correctly I will work on the data column format. So for this sample to work correctly user would open web from and click on button "Load Grid" when this is clicked it calls the the [webmethod] on the server, the sever then gets the data and passes it back to the jquery .ajax call and then it gets loaded into the jqGrid.
[Code]....
and the codebehind
[Code]....
View 2 Replies
Feb 25, 2016
I am trying to implement your code in "Calling ASP.Net WebMethod using jQuery AJAX", but the alert is giving me the value "Undefined".
I believe my website (asp.net c#) is not correctely configured for webmethods.
View 1 Replies
May 7, 2015
My problem is that I have a jqury function basically I want to add gridview row into data base .so that pupose I am doing that by accessing webmethod ,but the web method can’t call from that code .
My data can’t save into data base I will check it.value should be passed but problem is that this function can’t call webmethod I will check it doing debudg.
my function should be call webmethod
Following my code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"> </script>
<script type="text/javascript">
$(function () {
[Code].....
View 1 Replies
Sep 10, 2012
This is regarding your article onÂ
[URL]
I have a json object with multiple Name & Value pairs, Â I am using example on above given link but it is not calling the Web Method.
var jd = [];
jd.push({ ID: HArr[j], Val: Str });
var jd = [];
[Code].....
In my class I have a Web Method defined as :
[System.Web.Services.WebMethod]
public static jsonData PassJsonData(jsonData jd)
{
return jd;
}
View 1 Replies
Jan 29, 2011
By using AJAX am trying to call a webmethod in Code behind. In that webmethod I want to put some dynamic grid data and text box data to session. But WEBMETHOD is static, so we wont get access to Session and web controls. Is there any other method to achieve that goal.in window.onbeforeunload calling a script, that script calls a webmethod. This is the procedure i am following.
View 12 Replies
Dec 10, 2010
my page Evaluation.aspx has this code
[Code]....
and I am calling the webmethod by javascript like this
[Code]....
The result is, I get the error function running and I get "undefined error" alert.Am I calling the procedure correctly? I put a breakpoint on the webmethod and it.
View 1 Replies
Mar 1, 2011
I am new to jqGrid and I have found it difficult to follow the documentation jqGrid Documentation / I cannot figure out how to call a WebMethod when setting up the JQGrid. I have been successful in making an Ajax call to get the data and then setting up the JQGrid with local data. I think its an extra step in the setup process and that I should be able to provide the path to the webmethod using the url property. The editurl property is the same way. I am never actually receiving the post to the server. Attempted JQGrid Setup
function GetData()
{
$('#list').jqGrid({
type: "POST",
url: "Default.aspx/GetUsersJSON",
datatype: "json",
height: 250,
colName: ['Username', 'Email'],
colModel: [
...
}).jqGrid(
'navGrid',
'#pager',
{
edit: true,
add: true,
del: true
});
}
WebMethod
[WebMethod]
public static string GetUsersJSON()
{
var users = new List();
using(UserAdministrationSandboxDataContext uasd = new UserAdministrationSandboxDataContext())
{
users = uasd.GetUserList();
}
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize(users);
}
Current Code I got it working correctly now, but I still have one final question. Why did I have to set the 'repeatitems: false' in order to display the content? Some of the caveats to get this to work include the different ways to setup the ajax request. (Ajax: type) is (jqgrid : mtype) (Ajax: contentType) is (jqgrid : ajaxGridOptions: { contentType: })
And finally understanding the documentation from the documentation on how to setup the JSONReader.
function GetUserDataFromServer()
{
$('#list').jqGrid({
url: "Default.aspx/GetUsersJSON",
mtype: 'POST',
ajaxGridOptions: { contentType: "application/json" },
datatype: "json",
serializeGridData: function (postData)
{
return JSON.stringify(postData);
},
jsonReader: {
root: function (obj) { return obj.d; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.d.length; },
id:'0',
cell:'',
repeatitems: false
},
datatype: "json",
height: 250,
colName: ['Username', 'Email'],
colModel: [
{
name: 'Username',
index: 'Username',
width: 100,
editable: true
},
{
name: 'Email',
index: 'Email',
width: 220,
editable: true
},
{
name: 'IsLockedOut',
index: 'IsLockedOut',
width: 100,
editable: true,
edittype: 'checkbox'
}
],
caption: "Users"
})
}
Web Method
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static List GetUsersJSON()
{
using (UserAdministrationSandboxDataContext uasd = new UserAdministrationSandboxDataContext())
{
return uasd.GetUserList();
}
}
One JSON Object from the List
{"__type":"UserAdministrationSandbox.UserData","PKID":"00000000-0000-0000-0000-000000000001","Username":"TestUser","ApplicationName":"Test","Email":"TestUser@test.com","Comment":"TestUser","Password":"D41D8CD98F00B204E9800998ECF8427E","PasswordQuestion":"Is this a blank Password?","PasswordAnswer":null,"IsApproved":true,"LastActivityDate":"/Date(1298869200000)/","LastLoginDate":"/Date(1298869200000)/","LastPasswordChangedDate":"/Date(1298869200000)/","CreationDate":"/Date(1298869200000)/","IsOnLine":false,"IsLockedOut":false,"LastLockedOutDate":"/Date(1298869200000)/","FailedPasswordAttemptCount":0,"FailedPasswordAttemptWindowStart":null,"FailedPasswordAnswerAttemptCount":null,"FailedPasswordAnswerAttemptWindowStart":null}
View 1 Replies
Jan 14, 2011
I have a web Method in my C# that is called via Jquery ajax method. The web method should return an object back to the Jquery which will be used to populate. I have tried returning a JsonResult object, the actual object and nothing seems to work! I'm not using MVC (Unfortunately). Is there a way that I can return an object from my web method which can be used by my AJAX method? here is the link for my JQuery AJAX method [URL]
View 1 Replies
Nov 11, 2010
I use this test code and it works well :
JQuery
$(document).ready(function () {
$("#Result").click(function () {
$.ajax({
type: "POST",
url: "test-JQuery-Page-Methods.aspx/GetInfo",
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#Label1").text(msg.d);
}
});
});
});
.VB
<WebMethod()> Public Shared Function GetInfo() As String
Return "test"
End Function
Now i try to pass an argument to the function but something is wrong in my code and i dont know what is wrong... :
JQuery
$(document).ready(function () {
$("#Result").click(function () {
var textj = 'test';
var jsonText = JSON.stringify(textj);
$.ajax({
type: "POST",
url: "test-JQuery-Page-Methods.aspx/GetInfo",
data: jsonText,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#Label1").text(msg.d);
}
});
});
});
.VB
<WebMethod()> Public Shared Function GetInfo(ByVal infostring As String) As String
Return infostring
End Function
View 5 Replies
Jul 6, 2010
I have 2 web pages edit.aspx and webmethods.apx. In edit.aspx there is some jquery code to get some data :
[Code]....
With this I try to get a Json object from the webmethods.aspx page :
[Code]....
I get an error back that says "Parser Error", I even did put an breakpoint on the webmethod but it is like it's never triggered. Is my url wrong if I'm in the following url :
[Code]....
Should I use something like ../WebMethods.aspx?
View 6 Replies