locked
Send html form data to a class file RRS feed

  • Question

  • User535557118 posted

    I have to send my html form data to a class file. Is there any way we could do this. Any suggestions are appreciated.

    Friday, April 25, 2014 1:09 AM

Answers

  • User-933407369 posted

    hi,

    i would suggest you try checking out the codes:

    public void ProcessRequest(HttpContext context)
    
            {
    
                if (context.Request.Files.Count > 0)
    
                {
    
                    HttpFileCollection SelectedFiles = context.Request.Files;
    
                    for (int i = 0; i < SelectedFiles.Count; i++)
    
                    {
    
                        HttpPostedFile PostedFile = SelectedFiles[i];
    
                        string FileName = context.Server.MapPath("~/UploadedFiles/" + PostedFile.FileName);
    
                        PostedFile.SaveAs(FileName);                    
    
                    }
               //here add your codes
    
                } 
    
                else
    
                {
    
                    context.Response.ContentType = "text/plain";
    
                    context.Response.Write("Please Select Files");
    
                } 
    
                context.Response.ContentType = "text/plain";
    
                context.Response.Write("Files Uploaded Successfully!!");
    
            }
    

    please refer to the link :

    Uploading Multiple Files Using jQuery and Generic Handler in ASP.Net 4.5

    http://www.c-sharpcorner.com/UploadFile/4b0136/uploading-multiple-files-using-jquery-and-generic-handler-in/

    Hope it helps you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 28, 2014 3:36 AM

All replies

  • User-1025250470 posted

    Pleae check below link, it may help you.

    http://forums.asp.net/t/1391783.aspx?ASP+NET+Get+Page+HTML

    Thank You

    Friday, April 25, 2014 8:48 AM
  • User535557118 posted

    Sorry, this is not helpful... I'm trying to find a way to pass a form value to a class file c#.

    Friday, April 25, 2014 10:19 AM
  • User-1025250470 posted

    You mean html control value to a class? 

    Add runat="Server" tag on HTML Control

    <input id="txtInput" type="text" runat="server" />

    Get Value on Code behind

    String inputvalue= txtInput.value;

    You can pass this value to function/method parameters.

    Hope it help you

    Saturday, April 26, 2014 7:09 AM
  • User-163012697 posted

    Simply create a method, as i want to pass my name to Class file then:

    in .aspx.cs page:

    string myname=textbox1.text;

    // for Access the method mentioned in class file 

    initialize class file: 

    Class1 cs=new Class1();

    cs.GetData(myname);

    Now in class file:

    public void GetData(string name)

    {

    // use name where you want

    }

    Sunday, April 27, 2014 5:54 AM
  • User535557118 posted

    Sorry, about the confusion. My question must be misleading. 

    I have an upload control (javapowupload) on as aspx page. I have a class file which does all the file processing script. Each file is processed at once.  I need to send the total file count to the class file so that once all the files are uploaded(this is where the total file count can be used), I can write upload summary to the database. 

    I can communicate with the control using javascript. I have the file count in a varaible. But I do not know how to send the file count to that class file. Hope I am clear. Any help is appreciated.

    Sunday, April 27, 2014 5:47 PM
  • User-933407369 posted

    hi,

    i would suggest you try checking out the codes:

    public void ProcessRequest(HttpContext context)
    
            {
    
                if (context.Request.Files.Count > 0)
    
                {
    
                    HttpFileCollection SelectedFiles = context.Request.Files;
    
                    for (int i = 0; i < SelectedFiles.Count; i++)
    
                    {
    
                        HttpPostedFile PostedFile = SelectedFiles[i];
    
                        string FileName = context.Server.MapPath("~/UploadedFiles/" + PostedFile.FileName);
    
                        PostedFile.SaveAs(FileName);                    
    
                    }
               //here add your codes
    
                } 
    
                else
    
                {
    
                    context.Response.ContentType = "text/plain";
    
                    context.Response.Write("Please Select Files");
    
                } 
    
                context.Response.ContentType = "text/plain";
    
                context.Response.Write("Files Uploaded Successfully!!");
    
            }
    

    please refer to the link :

    Uploading Multiple Files Using jQuery and Generic Handler in ASP.Net 4.5

    http://www.c-sharpcorner.com/UploadFile/4b0136/uploading-multiple-files-using-jquery-and-generic-handler-in/

    Hope it helps you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 28, 2014 3:36 AM