image catptured by webcam on popup page and transfer from popup page to parent page after crop image according to requirment. The image is transferred from the popup page to the parent page. And appears on the image control but shows the image control null when I press the save button.
i have used below javascript code to transfer image from popup page to parent page image tranfer from popup page to parent page but when i press save button it showing image value are null. image display on image control but value display null...
parent page code..
<script> function myFunction() { var url = "/captureimage.aspx"; var s = window.open(url, 'popup_window', 'width=900,height=500,left=200,top=100,resizable=no'); ClientScript.RegisterStartupScript(this.GetType(), "script", s, true); } function SetSource(src) { document.getElementById("vImage").src = src; document.getElementById("vimagehidden").value = src; } </script>
popup page code
<script type="text/javascript"> function passDetails() { if (window.opener != null && !window.opener.closed) { alert('begin'); var vImage = window.opener.document.getElementById("vImage"); window.opener.SetSource(document.getElementById("imgCapture").src); } window.close(); } </script>
save code on parent page
protected void btnSubmit_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(vImage.ImageUrl)) { string filePath = Server.MapPath(vImage.ImageUrl); FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); BinaryReader br = new BinaryReader(fs); byte[] bytes = br.ReadBytes((Int32)fs.Length); br.Close(); fs.Close(); SqlConnection con = new SqlConnection(@"conne string"); //insert the file into database string strQuery = "INSERT INTO empDetails(name,mono,vimage) VALUES (@name,@mono, @vimage)"; SqlCommand cmd = new SqlCommand(strQuery, con); cmd.Parameters.AddWithValue("@name", txtName.Text.ToUpper()); cmd.Parameters.AddWithValue("@mono", txtContact.Text.ToUpper()); cmd.Parameters.Add("@vimage", SqlDbType.VarBinary).Value = bytes; con.Open(); cmd.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert('Record Saved !')</script>"); txtName.Text = ""; txtContact.Text = ""; vImage.ImageUrl = ""; } else { Response.Write("<script>alert('Capture Image!')</script>"); } }