Thursday, 8 August 2013

upload image, then use uploaded image to replace current background image in .ascx file

upload image, then use uploaded image to replace current background image
in .ascx file

I need to be able to upload an image and then have my uploaded image
replace the current background div. This must be done from an .ascx file.
Here is all my current relevant code from my WebUserControl.ascx:
<div class="box">
<img
src="EnergyOilGas-ProductionEnhanced-Oil_Natural-Gas-Recovery_flow_diagram3.jpg"
id="myimage" alt="image" height="800px" width="1700px" style="position:
absolute;"/>
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
</div>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Upload" />
And my .css for the element I am trying to change:
.box
{
border: 1px solid blue;
margin-bottom: 8px;
width: 1700px;
height: 800px;
float: none;
clear: both;
background-image:
url('EnergyOilGas-ProductionEnhanced-Oil_Natural-Gas-Recovery_flow_diagram3.jpg');
}
And my code behind (WebUserControl.ascx.cs):
protected void Button2_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null)
{
string fileExt =
System.IO.Path.GetExtension(FileUpload1.FileName);
if (fileExt == ".jpeg" || fileExt == ".jpg")
{
string FileName =
Path.GetFileName(FileUpload1.PostedFile.FileName);
string conn4 = "Host=172.21.98.153; Database=UAT_smartcomm;
UserName=iDacAdmin; Password=iDacAdmin2008; port=3306; allow
zero datetime = yes";
string upload = "INSERT INTO ScadaImages (FileName, fileExt)
VALUES (" + FileName + ", " + fileExt + ")";
DataBase.DataBaseIO.Save(conn4, upload);
string defaultImg =
"EnergyOilGas-ProductionEnhanced-Oil_Natural-Gas-Recovery_flow_diagram3.jpg";
string uploadedImg = "" + FileName + "" + fileExt + "";
Image.DisabledCssClass.Replace(defaultImg, uploadedImg);
}
}
}
The idea is to set whatever image the user uploads as the new background
image, replacing the current one. I know that the background image element
is stored in .box and I am unsure as to whether or not this also requires
a function, in addition to a code behind method. I have been stuck on this
for days. If anyone can help me, I would be much obliged.

No comments:

Post a Comment