Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi everyone..
i have to upload a file through handler...at that same time i should additionally
insert the drop down value..but while hit the breakpoint in handler file,code is not running..
i have written the following code

XML
asp.net code:
<asp:DropDownList ID="ddlproduct" runat="server">
        <asp:ListItem>select</asp:ListItem>
            <asp:ListItem>product1</asp:ListItem>
            <asp:ListItem>product2</asp:ListItem>
            <asp:ListItem>product3</asp:ListItem>
        </asp:DropDownList>
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
<asp:Button ID="Button1" runat="server" Text="submit" /></td>





jquery code:
<script type="text/javascript">
    $("document").ready(function () {
        $("#Button1").click(function () {
            var ddls = $("#ddlproduct option:selected").text();
            var fileUpload = $("#FileUpload1").get(0);
            var files = fileUpload.files;

            var data = new FormData();
            for (var i = 0; i < files.length; i++) {
                data.append(files[i].name, files[i]);
            }




//ajax code to send the file to handler
 $.ajax({
                url: "Handler.ashx",
                type: "post",
                data: {
                    action: insert,
                    ddl: ddls,
                    Data: data

                },
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    alert(response.d);
                },
                failure: function (response) {
                    alert("failure");
                }

            });

        });
        return false;
    });





here is the handler code:

public class Handler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {

          string action = context.Request["action"].ToString().Trim();
          if (action == "insert")
        {

            if (context.Request.Files.Count == 1)
                {

                    HttpPostedFile file = context.Request.Files[0];
                    file.SaveAs(context.Server.MapPath(file.FileName));
                    //context.Response.Write("File uploaded");
                }


            string ddlp = HttpUtility.HtmlEncode(context.Request["ddl"].ToString().Trim());

        ......sql queries etc



        }
    }


    public bool IsReusable {
        get {
            return false;
        }
    }



but i am facing two problems...
1.)while doing this,output page is loading(the page should not get loaded,because i am using handler method)
2.)while hit the breakpoint in handler file,the run flow is not going to handler file


anyone pls help me..
thanks in advance..
Posted
Updated 16-Jul-14 1:36am
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900