Jump to content

image control


vj5

Recommended Posts

I have an image control on my form and also a file upload control. when i click on the browse button and select a image, that image should appear in the image control. how do i do? please help. thanks.

Link to comment
Share on other sites

You would have to go further than just selecting an image with the browse button. You would have to upload it to the server and then specify that new server path in the image control. The image is being selected from the client's pc and the image control is loaded from the server.

Link to comment
Share on other sites

You would have to go further than just selecting an image with the browse button. You would have to upload it to the server and then specify that new server path in the image control. The image is being selected from the client's pc and the image control is loaded from the server.
Is there a way to do without uploading the image to the server?
Link to comment
Share on other sites

After a little playing I got something to work. I have included a plain HTML version and an ASP.Net version.plain HTML

<input type="file" name="upload" id="upload" onchange="onFileSelected(this)"/><br/><img alt="" id="preview"/><script type="text/javascript">	function onFileSelected(input) {		var preview = document.getElementById('preview');		if(document.all) { preview.src = input.value; } //IE		else { preview.src = 'file:///' + input.value; } //firefox, etc	}</script>

ASPX

<asp:FileUpload id="FileUpload1" runat="server" onchange="onFileSelected(this)"/><br/><asp:Image id="PreviewImage" runat="server"/><script type="text/javascript">	function onFileSelected(input) {		var preview = document.getElementById('<%= PreviewImage.ClientID %>');		if(document.all) { preview.src = input.value; } //IE		else { preview.src = 'file:///' + input.value; } //firefox, etc	}</script>

Link to comment
Share on other sites

After a little playing I got something to work. I have included a plain HTML version and an ASP.Net version.plain HTML
<input type="file" name="upload" id="upload" onchange="onFileSelected(this)"/><br/><img alt="" id="preview"/><script type="text/javascript">	function onFileSelected(input) {		var preview = document.getElementById('preview');		if(document.all) { preview.src = input.value; } //IE		else { preview.src = 'file:///' + input.value; } //firefox, etc	}</script>

ASPX

<asp:FileUpload id="FileUpload1" runat="server" onchange="onFileSelected(this)"/><br/><asp:Image id="PreviewImage" runat="server"/><script type="text/javascript">	function onFileSelected(input) {		var preview = document.getElementById('<%= PreviewImage.ClientID %>');		if(document.all) { preview.src = input.value; } //IE		else { preview.src = 'file:///' + input.value; } //firefox, etc	}</script>

Thankyou so much for the taking the trouble to write up a javascript. I am gettting an error "
Compiler Error Message: BC30451: Name 'PreviewImage' is not declared.Source Error: Line 9:	  function onFileSelected(input) {Line 10:	 [color="#FF0000"]Line 11:	 var preview = document.getElementById('<%= PreviewImage.ClientID %>');[/color]Line 12:		 if(document.all) { preview.src = input.value; } //IELine 13:		 else { preview.src = 'file:///' + input.value; } //firefox, etc

Link to comment
Share on other sites

my code:

<asp:FileUpload ID="picturefile" runat="server" onchange="onFileSelected(this)"/> <asp:Image ID="Image1" runat="server" /><head><script type="text/javascript">	function onFileSelected(input) {		var preview = document.getElementById('<%= Image1.ClientID %>');		if(document.all) { preview.src = input.value; } //IE		else { preview.src = 'file:///' + input.value; } //firefox, etc	}		</script></head>

Link to comment
Share on other sites

it works fine if I open the html version in the browser but if I try and view it over localhost (running on a web server) it doesn't work. Probably security settings preventing JavaScript from accessing local files without permission. There's nothing you can do to get around that.

Link to comment
Share on other sites

it works fine if I open the html version in the browser but if I try and view it over localhost (running on a web server) it doesn't work. Probably security settings preventing JavaScript from accessing local files without permission. There's nothing you can do to get around that.
I am using aspx file and and it gives error that onchange event is not supported by asp control.
Link to comment
Share on other sites

I have almost no knowledge about ASP.NET but this article shows you how to add client-side attributes to ASP.NET controls: http://aspnet.4guysfromrolla.com/articles/021104-1.aspxThis won't fix aspnetguy's issue though.

Link to comment
Share on other sites

I have almost no knowledge about ASP.NET but this article shows you how to add client-side attributes to ASP.NET controls: http://aspnet.4guysfromrolla.com/articles/021104-1.aspxThis won't fix aspnetguy's issue though.
I am pretty sure this is a security limitation. JavaScript is not allowed to access resources ont he users PC with COM+ or ActiveX. I doubt this can be done unless the file is first uploaded to the server. This applies to all server side languages not just ASP.Net. It's actually a client side limitation that has nothing to do with the server.
Link to comment
Share on other sites

Can someone give me a simplest way to display image in the form stored in the database as path?
ASPX
<asp:Image id="SomeImage" runat="server" />

C#

string imagepath = GetImagePathFromDatabaseUsingTheMethodOfYourChoice();SomeImage.ImageUrl = imagepath;

Link to comment
Share on other sites

ASPX
<asp:Image id="SomeImage" runat="server" />

C#

string imagepath = GetImagePathFromDatabaseUsingTheMethodOfYourChoice();SomeImage.ImageUrl = imagepath;

Where should I write the c# code - in page load?What do you mean by this? - getimagepathfromdatabaseusingthemethodofyourchoice();Can you give an example? what is someImage?
Link to comment
Share on other sites

Where should I write the c# code - in page load?What do you mean by this? - getimagepathfromdatabaseusingthemethodofyourchoice();Can you give an example? what is someImage?
I am getting a lot of errors of which one of them is :Error 1 'String' is a class type and cannot be used as an expression. What should I do for that error?And also I used the path to the database in imagepath, it gives me error to declare each one of the item...
Link to comment
Share on other sites

string imagepath = path/to/the/database/tblphonelist() Image1.ImageUrl = imagepath
Are you serious? It appears like you don't have an understanding of the most basic operations of this language. Please read the tutorial on ASP.Net. It explains how to get data out of a database
Link to comment
Share on other sites

Are you serious? It appears like you don't have an understanding of the most basic operations of this language. Please read the tutorial on ASP.Net. It explains how to get data out of a database
I am new to asp.net. I have given the connection string to retrieve data but not sure what to do after that.Will read the tutorial. thanks.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...