Showing posts with label image. Show all posts
Showing posts with label image. Show all posts

Monday, March 26, 2012

pass value to image control

This is my first time to use asp.net. I just want to get an image name passed from url (by using request.querystring), and then display this image, when user click the image, I also display the mouse coordinate. But I just can not get it to work, please help. Thanks. The following is my code:

<script runat="server">
Sub getCoordinates(sender As Object, e As ImageClickEventArgs)
mess.Text="Coordinates: " & e.x & ", " & e.y
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim imagename as String = Request.QueryString("name")
Dim imagePath as String =Server.MapPath("/keller/portrait/" & imagename)
End Sub
</script>
<html>
<body>
<form runat="server">
<p>Click on the image:</p>
<asp:Image
runat="server"
ImageUrl="<%=iamgePath%>"
OnClick="getCoordinates"/>
<p><asp:label id="mess" runat="server"/></p>
</form>
</body>
</html>
Welcome to the ASP.NET Forums, lily1.

The following update to your code will correctly show the image passed in with the QueryString.

<%@. page language="VB" debug="true" %>
<html>
<head>
<title>This is main Page</title>
<script runat="server"
Sub getCoordinates(sender As Object, e As ImageClickEventArgs)
mess.Text="Coordinates: " & e.x & ", " & e.y
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim imagename as String = Request.QueryString("name")
Dim imagePath As String = Server.MapPath("/keller/portrait/" & imagename & ".gif")
MyImage.ImageUrl = imagePath
End Sub

</script>
<html>
<body>
<form runat="server">
<p>Click on the image:</p>
<asp:Image runat="server"
id="MyImage"
OnClick="getCoordinates" />
<p><asp:label id="mess" runat="server" /></p>
</form>
</body>
</html>

The only difference is that I gave the asp:Image control an ID, and used this ID in your Page_Load code to set its ImageUrl property.

For details of how to get your imagemap working, see the following tutorial:
ImageMap.NET

I hope this helps.
Thanks for your help. I tried your script, The picture can be displayed correctly now, but when i click the picture, I got javascript error, it seems that function 'getCoordinates' does not execute at server instead it tries to run at client side. Here is url of the page:http://user1046822.wx15.registeredsite.com/keller/imagecrop_coodinates.aspx?name=test.jpg . Could you please tell me what is the problem? Thanks again.
> Could you please tell me what is the problem?

You've defined the problem yourself ... that getCoordinates tries to run at the client-side, not at the server.

Please go through the article I provided above. That will explain how to send click coordinates back to your server-side code.

Wednesday, March 21, 2012

Passing a javascript array to a handler .ashx

I am using a handler (processImage.ashx) to display an image. The image is
displayed according to parameters passed in the querystring. The handerl is
called via some clientside javascript.
I want to send an array of unknown length to the handler. I am not sure
whether the querystring is the best place to do this. What's the best way to
send an array held in the client side javascript to the handler?
Thanks in advance,
JJyou can not post an image request, so the url is the only option other than
a
prelimary ajax call. the url is restricted to about 2k. how you encode the
array depends on the array type. the most common is a array.join('|'), with
a
matching split on the server side.
-- bruce (sqlwork.com)
"JJ" wrote:

> I am using a handler (processImage.ashx) to display an image. The image is
> displayed according to parameters passed in the querystring. The handerl i
s
> called via some clientside javascript.
> I want to send an array of unknown length to the handler. I am not sure
> whether the querystring is the best place to do this. What's the best way
to
> send an array held in the client side javascript to the handler?
> Thanks in advance,
> JJ
>
>
How would I do the prelimary ajax call?
Thanks,
JJ
"bruce barker (sqlwork.com)"
<brucebarkersqlworkcom@.discussions.microsoft.com> wrote in message
news:C8495134-FF6B-4D8B-82C1-FE5F393D6454@.microsoft.com...
> you can not post an image request, so the url is the only option other
> than a
> prelimary ajax call. the url is restricted to about 2k. how you encode the
> array depends on the array type. the most common is a array.join('|'),
> with a
> matching split on the server side.
> -- bruce (sqlwork.com)
>
> "JJ" wrote:
>
Hi JJ,
I think Bruce means you should pass the image urls(or any array parameters)
either through url querystring or through AJAX xmlhttp request. Directly
manipulate binary content of image is not quite supported in client script
and also not effecient to pass such large content frequently.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
--
>From: "JJ" <abc@.xyz.com>
>Subject: Re: Passing a javascript array to a handler .ashx
>Date: Tue, 20 Nov 2007 10:55:18 -0000

>How would I do the prelimary ajax call?
>Thanks,
>JJ
>"bruce barker (sqlwork.com)"
><brucebarkersqlworkcom@.discussions.microsoft.com> wrote in message
>news:C8495134-FF6B-4D8B-82C1-FE5F393D6454@.microsoft.com...
the
handerl
way
>
>

Passing a javascript array to a handler .ashx

I am using a handler (processImage.ashx) to display an image. The image is
displayed according to parameters passed in the querystring. The handerl is
called via some clientside javascript.

I want to send an array of unknown length to the handler. I am not sure
whether the querystring is the best place to do this. What's the best way to
send an array held in the client side javascript to the handler?

Thanks in advance,
JJyou can not post an image request, so the url is the only option other than a
prelimary ajax call. the url is restricted to about 2k. how you encode the
array depends on the array type. the most common is a array.join('|'), with a
matching split on the server side.

-- bruce (sqlwork.com)

"JJ" wrote:

Quote:

Originally Posted by

I am using a handler (processImage.ashx) to display an image. The image is
displayed according to parameters passed in the querystring. The handerl is
called via some clientside javascript.
>
I want to send an array of unknown length to the handler. I am not sure
whether the querystring is the best place to do this. What's the best way to
send an array held in the client side javascript to the handler?
>
Thanks in advance,
JJ
>
>
>


How would I do the prelimary ajax call?

Thanks,
JJ
"bruce barker (sqlwork.com)"
<brucebarkersqlworkcom@.discussions.microsoft.comwro te in message
news:C8495134-FF6B-4D8B-82C1-FE5F393D6454@.microsoft.com...

Quote:

Originally Posted by

you can not post an image request, so the url is the only option other
than a
prelimary ajax call. the url is restricted to about 2k. how you encode the
array depends on the array type. the most common is a array.join('|'),
with a
matching split on the server side.
>
-- bruce (sqlwork.com)
>
>
"JJ" wrote:
>

Quote:

Originally Posted by

>I am using a handler (processImage.ashx) to display an image. The image
>is
>displayed according to parameters passed in the querystring. The handerl
>is
>called via some clientside javascript.
>>
>I want to send an array of unknown length to the handler. I am not sure
>whether the querystring is the best place to do this. What's the best way
>to
>send an array held in the client side javascript to the handler?
>>
>Thanks in advance,
>JJ
>>
>>
>>


Hi JJ,

I think Bruce means you should pass the image urls(or any array parameters)
either through url querystring or through AJAX xmlhttp request. Directly
manipulate binary content of image is not quite supported in client script
and also not effecient to pass such large content frequently.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

-------

Quote:

Originally Posted by

>From: "JJ" <abc@.xyz.com>
>Subject: Re: Passing a javascript array to a handler .ashx
>Date: Tue, 20 Nov 2007 10:55:18 -0000


Quote:

Originally Posted by

>How would I do the prelimary ajax call?
>
>Thanks,
>JJ
>"bruce barker (sqlwork.com)"
><brucebarkersqlworkcom@.discussions.microsoft.comwro te in message
>news:C8495134-FF6B-4D8B-82C1-FE5F393D6454@.microsoft.com...

Quote:

Originally Posted by

>you can not post an image request, so the url is the only option other
>than a
>prelimary ajax call. the url is restricted to about 2k. how you encode


the

Quote:

Originally Posted by

Quote:

Originally Posted by

>array depends on the array type. the most common is a array.join('|'),
>with a
>matching split on the server side.
>>
>-- bruce (sqlwork.com)
>>
>>
>"JJ" wrote:
>>

Quote:

Originally Posted by

>>I am using a handler (processImage.ashx) to display an image. The image
>>is
>>displayed according to parameters passed in the querystring. The


handerl

Quote:

Originally Posted by

Quote:

Originally Posted by

Quote:

Originally Posted by

>>is
>>called via some clientside javascript.
>>>
>>I want to send an array of unknown length to the handler. I am not sure
>>whether the querystring is the best place to do this. What's the best


way

Quote:

Originally Posted by

Quote:

Originally Posted by

Quote:

Originally Posted by

>>to
>>send an array held in the client side javascript to the handler?
>>>
>>Thanks in advance,
>>JJ
>>>
>>>
>>>


>
>
>