Click here to Skip to main content
15,904,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i click the download(link button) in grid view am showing a pop up box(to valide mobile number am sending OTP to mobile ,in pop up box i have Text box and button control ) ,
when i submit otp in pop up if he is a valid then start download document if not show error message


am getting error as
when i click download , pop up is showing and download also starting
but i want to verify user in pop up , when he submit valid otp then download should start
ASP.NET
<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="#cccccc" HeaderStyle-ForeColor="Black"
                        RowStyle-BackColor="white" RowStyle-ForeColor="#003366" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000"
                        AutoGenerateColumns="false" Font-Bold="False">
                        <Columns>
                            <asp:BoundField DataField="UserName" HeaderText="User Name" />
                            <asp:BoundField DataField="DocumentType" HeaderText="Document Type" />
                            <asp:BoundField DataField="FormType" HeaderText="Form Type" />
                            <asp:BoundField DataField="Description" HeaderText="Description" />

                            <asp:TemplateField ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="DownloadFile" OnClientClick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';"
                                        CommandArgument='<%# Eval("Id") %>'></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>



cs code

C#
protected void DownloadFile(object sender, EventArgs e)
    {
       
        //if (txtOtp.Text == txtName.Text)
        //{

            int id = int.Parse((sender as LinkButton).CommandArgument);
            byte[] bytes;
            string DocumentType, FormType, fileName, Description, contentType;
            string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
            cmd.CommandText = "select UserName,DocumentType,FormType,Name, Data, ContentType,Description from tblFiles ";
            cmd.Parameters.AddWithValue("@Id", id);
            cmd.Connection = con;
            con.Open();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                sdr.Read();
                bytes = (byte[])sdr["Data"];
                DocumentType = sdr["DocumentType"].ToString();
                FormType = sdr["FormType"].ToString();
                contentType = sdr["ContentType"].ToString();
                fileName = sdr["Name"].ToString();
                Description = sdr["Description"].ToString();
            }

            con.Close();


            Response.Clear();
            Response.Buffer = true;
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = contentType;
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();
        //}
        //else
        //{
        //     Response.Write("&lt;script&gt; alert('wrong otp.......')&lt;/script&gt;");
        //}
       }
Posted
Updated 11-Jan-16 22:39pm
v3
Comments
F-ES Sitecore 12-Jan-16 4:48am    
There is nothing in your code that shows a pop-up? The LinkButton calls the download file code which downloads the file. I'm struggle to understand why this isn't seemingly obvious?

You'll need something that shows a pop-up when you click the download link and in that pop-up you'll need a form (or some other mechanism) that verifies the user based on the OTP and if successful it will then call the download code you currently have. How that works depends on what you use to drive your pop-op. You could use the ajaxtoolkit popup extender, or a jQuery pop-up....lots of options.
Richard Deeming 12-Jan-16 9:29am    
There's also nothing in your code that validates the user's OPT.

And you seem to be missing a WHERE clause in your query - you've added a parameter to select a specific file, but you've never used it in the query.
[no name] 12-Jan-16 11:21am    
In your aspx page code, add how do you design for "light" div pop up.

Do "Improve Question" and append HTML code.
yourfriendaks 15-Jan-16 6:44am    
why you are calling downloadfile method on link button?

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