.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Get and Post method in C#

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :ASP.Net

I need an example of GET and POST methods for C #?

whether one can explain it in a textbox how it works.

Thank you in advance

View Complete Post

More Related Resource Links

Overload POST with X-HTTP-Method-Override as DELETE

Hi, How do I pass POST with the override header, X-HTTP-Method-Override, which will say I really mean DELETE in REST WCF 3.5? What changes are needed exactly in server side REST code & where to make those changes exactly? Can some one post code snippet? Thanks!

Programatically Send and receive data using Post Method

Hi,I wish to make a script which programatically send the POST data to one server and then the other server receive the POST message and retrieve the information. How should make this work? I already successfully write the sender site, the code as follow:string postData = "id=0&co=5";ASCIIEncoding encode = new ASCIIEncoding();         //data encoding         byte[] dataEncode = encode.GetBytes(postData);         //end ascii encoding scheme         string url = "http://localhost:51711/Handler1.ashx"; //         //web request         HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);         req.Method = "POST";         req.ContentType = "application/x-www-form-urlencoded";         req.ContentLength = dataEncode.Length;         //send data                Stream st = req.GetRequestStream();         st.Write(dataEncode, 0, dataEncode.Length);         st.Close();ASCIIEncoding encode = new ASCIIEncoding();byte[] dataEncode = encode.GetBytes(postData);stri

create web service with http-post method


hi All,

we need to expose a web service to the 3rd party vendor which can only call using POST protocol, NOT SOAP.

So my question, is it better to build a web service or just simply .aspx page?

Also is there any best practice documentation on this.



Method 'Post' of object 'IOWSPostData' failed


I have Microsoft Office 2003 and Microsoft Sharepoint Designer 2007 on the
same machine. I have a problem uploading an excel spreadsheet into WSS 3.0.
I get Method 'Post' of object 'IOWSPostData' failed error. I have followed
this article (http://mindsharpblogs.com/Kathy/archive/2008/03/16/4450.aspx)
but it doesn't resolve the issue.
Pls, advise how can I resolve this.

Thank you in advance!


webinvoke method=Post..throws error "The remote server returned an error: (405) Method Not Allowed."



my service defn

      UriTemplate = "/CreateCustomer/cNo/{cNo}/cName/{cName}",
      Method = "POST")]
    bool InsertCustomer(string cNo, string cName);

/*service call*/

 public bool InsertCustomer(string cNo, string cName)
      bool Inserted;
      String connString = ConfigurationManager.ConnectionStrings["connectionstr"].ConnectionString;
      SqlConnection Conn = new SqlConnection(connString);
      SqlCommand Cmd = new SqlCommand();
      Cmd.Connection = Conn;
      Cmd.CommandText = "Insert into Customer Values(cid,cname)";
      Cmd.Parameters.AddWithValue("cid", Convert.ToInt32(cNo));
      Cmd.Parameters.AddWithValue("cname", cName);
      Inserted = Convert.ToBoolean(Cmd.ExecuteNonQuery());
      return Inserted;

/*client code */

  string ServiceUri = "http://localhost:portno/Service.svc/CreateCustomer/" + "cNo" + "/" + TextBox1.Text + "/" + "cName";
      WebRequest addRequest = WebRequest.Create(ServiceUri);
      addRequest.Method = "POST";
      addRequest.ContentType = "application/xml; charset=utf-8";
      addRequest.ContentLength = 0;
      WebResponse addResponse = addRequest.GetRespo

jQuery post to an action method



I hope this is the right section to post this, as it does seem to be an MVC related issue. I'm trying to use the jQuery.post() function to post an object to an action method, but for some reason the nested objects aren't initialised properly when they're received by the action method.

Here's my javascript code:

var data = {
    Id: 10,
    User: {
        Id: 5
$.post("/Home/SaveCompany", data, function (data) {

And my action method:

public ActionResult SaveCompany(Company company)
    if (company.Id > 0) {
    } else {
    return Json(new { id = company.Id });

company.Id has a value of 10, but company.User.Id is 0. Any ideas what I'm doing wrong? I've not named any properties incorrectly, by the way.


Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

Post back puzzle


Hi, I have a website where the user makes a selection from a combo box and it then fills a couple text boxes with text based upon the selection. I'm sure as you know it could take a second for the text to appear in the text box due to the post back. I know there is no way to make it instantanious, so what I would like to do it fill the text box with somthing like "Loading Info..." so the user does not type in it while the information is loading.

If you would like to see what I mean please go to this page: www.epiclinks.com/create.aspx and mess around with the combo boxes and You'll see what I mean.

What I would like to do is have it do a post back to write "Loading Info..." and then do another post back to fill it in based upon their selection. How would I do this?

I'm up for anything, so if you have a better solution than that please let me know.


Sys.Net.WebServiceFailedException: The server method '' failed with the following error:



Let's say we have 2 time consuming functions, aaa and aaa1 inside a aspx page.

        public static string aaa(int i)
            return i.ToString();

        public static string aaa1(int i)
            return i.ToString();



        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        <span id="displayspan"></span>
        <br />
        <input type="button" value=

Looking for ASP.Net JQuery Post Sample


Hi, iam looking for a JQuery Post Sample, without reload of the current Page. I want on a webform enter a search text, onclick on the submit button i want get (webservice?) back clean html code that will be shown in a div tag
i found something like

<form id="formsearch" onsubmit="jQuery.ajax({type:'POST',dataType:'html',data:jQuery(this).serialize(),success:
function(data, textStatus){jQuery('#ajaxcontent').html(data);},beforeSend:function(XMLHttpRequest){$('#indicatorSearch').
show();},complete:function(XMLHttpRequest, textStatus){$('#indicatorSearch').hide();},
url:'/Search'}); return false;" action="/Search" method="post">

but how is the source asp.net (or webservice) build up?

can you give me some samples, how i can realize that with asp.net


Jscript error: Object does not support property or method


 Hi, i have little knowledge on javascript but i need to use this code get from somewhere for a jquery to work.

I face this "Jscript runtime error: Object does not support property or method" whenever im trying to run this page.

In my experience, im get this error msg 9 out of 10 times i use javascript in my system.

Im using Microsoft Visual web developer 2008, i wonder if this is related to my problem, i not sure there is anything i need to add as reference or update anything.

But anyway, in short, i just couldn't use javascript code when using this development tool because of this sort of error.

Anyway, it happen that last time i tried use the same type of jquery code in another project and it seems to work well without an error.

But now when im try to use it again in this recent project i created, it come out with this error and i have no idea how to solve it even look through google and this forum.

It doesn't really seems like its the code problem itself although im not sure, because any javascript code just couldn't work.

So below is my code that i need to use.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
<script type="text/javascript" src=&quo

Using CreateNewUserWizard SendingMail method to email me, not applicatnt.


I have staff area of my site I am protecting with forms authentication using c# and .Net 4.0. What I want to do is let the staff members register on the site but instead of the confermation email being sent to them I want it sent to me so I can go in and approve it. I have been trying to use the SendingMail method  but can not figure out how to get it to email me instead of the person that registered. I have searched around this site and find many topics on the SendingMail method but none seem to properly address my issue. Can anyone help me out?

HTTP Post and WebService


I am working on a application which will accept the data in the post request. My application also wants to expose a web service and want to call another web service. Considering all these 3 action that I want to do, can I create a single application which will have a web form which will accept the POST request and expose a web service at the same time.

Although it may be possible to achieve this, Is this a correct way of doing it?

server side does not save data when using POST data to another URL using WebRequest


 I am using a IIS 7.5 on Windows 7. I have a simple application that uses System.Net.WebRequest to POST data to another URL (in fact, the server side URL is on my local computer and it is hosted in IIS 7.5).

  1.  The problem is the server does not save data from client although on the client side codes when I debug and I see the OK message return from the code line

   response.StatusDescription; // this has value of "OK"
2. How can I debug the server code side where to receive the request from client side who posts the data ?

The following is the codes for client who posts data using System.Net.WebRequest, and codes for server side who received posted data to save to database.

Client side codes: // also run on my local computer

public string PostIntegrationXml(XmlDocument xmlSubmitDoc)




statement cannot appear outside of a method body


hi all,

  i am posting my vb.net problem .plz tell me how to resolve this :-

Dim conn As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
    'Dim mysqlconnection As New SqlConnection(conn)
    'If mysqlconnection.State=ConnectionState.closed Then mysqlconnection.Open();
    'Dim mySqlcommand As New SqlCommand("select CategoryId,CategoryName from Categories", mysqlconnection)
    'Dim mySqlDataAdapter As New SqlDataAdapter(mySqlcommand)
    'Dim mydataSet As New DataSet()

    'if mysqlconnection.State=ConnectionState.closed Then mysqlconnection.Open();

i m getting 5 errors in this code

declaration expected in mySqlDataAdapter.Fill method; Gridview1.DataSource=ds; Gridview1.DataBind();

Question in Get method in C#


I got a recent working code from client.I see errors in the get methods when i compile , below are some place where the error happens.Can any one help me out?


Error 2 'System.Environment.NewLine.get': cannot explicitly call operator or accessor C:\Documents and Settings\shankar\My Documents\Visual Studio 2008\Projects\DKCLwin\DKCLwin\LocalizationAdmin.cs 150 170 DKCLwin

Error 2 'System.Environment.NewLine.get': cannot explicitly call operator or accessor C:\Documents and Settings\shankar\My Documents\Visual Studio 2008\Projects\DKCLwin\DKCLwin\LocalizationAdmin.cs 150 170

Toolbox: Database Documentation, API for Pre- and Post-Conditions, Blogs and More


In this month's column, Scott explores one-click database documentation, covers an API for pre- and post-conditions, takes a look at an interesting blog, and reviews the latest book about the ASP.NET MVC Framework.

Scott Mitchell

MSDN Magazine November 2009

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend