0

In my web application I have a master aspx page in that i have a button click on that btn click i am calling a ascx web user control in that I am using a javascript through which I am trying to post the data in the same ascx, as I know we can post data in ascx page.. but I want to post how is that possible?

xhr.open('POST', '../test.ascx?Id=' + <%=Id%>, true); //Id is the property in ascx page
xhr.setRequestHeader('FILENAME', file.name);
xhr.send(file);

and onInit ..

       if (!string.IsNullOrEmpty(Request.Headers["FileName"]))
        {
            string Name = Request.Headers["FileName"].ToString();
            Stream Stream1 = Request.InputStream;
            Add(Name, Stream1, Id);
        }
Rocky
  • 4,454
  • 14
  • 64
  • 119
  • 3
    ascx??? you can't access user controls because they are not accessible from external path.. you should be using httphandlers/webmethods.. see this http://stackoverflow.com/questions/579024/calling-an-ascx-page-method-using-jquery – Shoaib Shaikh Feb 22 '12 at 04:48
  • then how could I send the file to handler? – Rocky Feb 22 '12 at 04:54

3 Answers3

1

You can't post directly to an ascx control. You should post to the aspx page that contains the control. The page will automatically create a tree that contains the controls you've statically declared on the page (in the markup). Dynamic controls require special care.

After that, usually you would parse the incoming query string or POST data in an early event handler, such as Page_Load(), and make whatever calls you need to against the indicated control.

RickNZ
  • 18,448
  • 3
  • 51
  • 66
0

You should try using some jquery plugin that will help you to give progress and handler other events while uploading file async.. a good article on it http://blogs.technet.com/b/sateesh-arveti/archive/2010/11/19/ajax-file-upload-using-jquery.aspx

while there are similar SO questions you should look at:

How can I upload files asynchronously?

Regards.

Community
  • 1
  • 1
Shoaib Shaikh
  • 4,565
  • 1
  • 27
  • 35
  • have implemented drag and drop yourself? or using html5? if you could use a jquery plugin you should use http://blueimp.github.com/jQuery-File-Upload/ it supports drag and drop and multifile uploads. – Shoaib Shaikh Feb 22 '12 at 05:28
  • I have implemented drag nd drop my self..am using ajax/jQuery/jquery-1.6.1.min.js plugin – Rocky Feb 22 '12 at 06:42
0

we can't post directly to an ascx control. so i used handler to solve this problem..

xhr.open('POST', '../Controls/test1.ashx?Id=' + '<%=Id%>', true);
Rocky
  • 4,454
  • 14
  • 64
  • 119