Jump to content
Sign in to follow this  
vj5

image control

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.

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
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>

Share this post


Link to post
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

Share this post


Link to post
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>

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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;

Share this post


Link to post
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?

Share this post


Link to post
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...

Share this post


Link to post
Share on other sites
post your code so we can see what you have done.
string imagepath = path/to/the/database/tblphonelist() Image1.ImageUrl = imagepath

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...