Tuesday 27 June 2017

Login picture upload


<asp:UpdatePanelrunat="server">
<Triggers>
<asp:PostBackTriggerControlID="btnUpload"/>
</Triggers>
<ContentTemplate>
<label class="file-upload" id="lbupload" runat="server" onmouseover="MOver()" onmouseout="MOut()">

<asp:Imagerunat="server"ID="image1"ImageUrl="image/camera.png"Height="50px"
Width="50px"Style="display: none; margin-left: 50px"/>
<asp:FileUploadID="myfile"runat="server"onchange="UploadFile(this)"/>
<asp:ButtonID="btnUpload"runat="server"OnClick="btnUpload_Click"Style="display: none"/>
</label>
</ContentTemplate>
</asp:UpdatePanel>
<scripttype="text/javascript">

functionMOver() {
debugger;
document.getElementById('<%= image1.ClientID %>').style.display = "block";
document.getElementById('<%= lbupload.ClientID%>').style.opacity = "0.7";
        }
functionMOut() {
document.getElementById('<%= image1.ClientID %>').style.display = "none"
document.getElementById('<%= lbupload.ClientID%>').style.opacity = "1";
        }

</script>
<scripttype="text/javascript">
functionUploadFile(fileUpload) {
debugger
//varff = fileUpload.value;
//   var res = ff.slice(12);
//   var v = 'image/' + res;            
// document.getElementById('<%=ss.ClientID%>').style.backgroundImage = "url('" + v + "')";         
if (fileUpload.value != '') {
document.getElementById("<%=btnUpload.ClientID%>").click();
            }
        }
</script>
<style>
.file-upload {
cursor: pointer;
/*background-image: url(image/Tulips.jpg);*/
background-size: cover;
background-position: center;
border-radius: 50%;
width: 150px;
height: 150px;
border-style:solid;
border-color:#ded5d5;
border-width:thin;
        }
.file-uploadinput {
top: 0;
left: 0;
margin: 10px;
opacity: 0;
filter: alpha(opacity=0);
            }

</style>



protectedvoidbtnUpload_Click(object sender, EventArgs e)
        {
if (myfile.HasFile)
            {
myfile.SaveAs(Server.MapPath("~/image/" + Path.GetFileName(myfile.FileName)));
stringfileName = Path.GetFileName(myfile.FileName);
string v = "image/" + fileName;
ViewState["image"] = "~/image/" + fileName;
ss.Attributes.Add("style", "background-image: url('" + v + "');");
            }

        }



No comments:

Post a Comment