Showing posts with label request. Show all posts
Showing posts with label request. 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.

pass values

On my web page i'm passing in a value using request.querystring, but i need
this same value several other pages. How can I store this value and use it o
n my other pages to execute my SQL?
thxIn a session variable.
Eliyahu
"IGotYourDotNet" <IGotYourDotNet@.discussions.microsoft.com> wrote in message
news:C3EEF090-CC7C-4A13-83EF-C0D7A655B93E@.microsoft.com...
> On my web page i'm passing in a value using request.querystring, but i
need this same value several other pages. How can I store this value and use
it on my other pages to execute my SQL?
> thx
You say you're "passing in a value" - Where are you passing it from? Where
are you passing it to?
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"IGotYourDotNet" <IGotYourDotNet@.discussions.microsoft.com> wrote in message
news:C3EEF090-CC7C-4A13-83EF-C0D7A655B93E@.microsoft.com...
> On my web page i'm passing in a value using request.querystring, but i
need this same value several other pages. How can I store this value and use
it on my other pages to execute my SQL?
> thx
You can pass values between pages using a variety of methods - session
variables are common, as is using viewstate. I prefer to structure my code
really well and use properties via the refernce page directive. Theres a
small example below for you
Regards
John Timney
Microsoft Regional Director
Microsoft MVP
"IGotYourDotNet" <IGotYourDotNet@.discussions.microsoft.com> wrote in message
news:C3EEF090-CC7C-4A13-83EF-C0D7A655B93E@.microsoft.com...
> On my web page i'm passing in a value using request.querystring, but i
need this same value several other pages. How can I store this value and use
it on my other pages to execute my SQL?
> thx
PassingValuesPage.aspx
<%@. Page Language="VB" ClassName="FirstPageClass" %>
<html>
<head>
<script runat="server">
Public ReadOnly Property FirstName() As String
Get
' first is the name of a TextBox control.
Return first.Text
End Get
End Property
Public ReadOnly Property LastName() As String
Get
' last is the name of a TextBox control.
Return last.Text
End Get
End Property
Sub ButtonClicked(sender As Object, e As EventArgs)
Server.Transfer("ReceivingValuesPage.aspx")
End Sub
</script>
</head>
<body>
<form runat="server">
First Name:
<asp:TextBox id="first"
runat="server"/>
<br>
Last Name:
<asp:TextBox id="last"
runat="server"/>
<br>
<asp:Button
OnClick="ButtonClicked"
Text="Go to second page"
runat=server />
</form>
</body>
</html>
--recievingvalues.aspx
<%@. Page Language="VB" %>
<%@. Reference Page="passingValuesPage.aspx" %>
<html>
<head>
<script runat="server">
Dim fp As FirstPageClass
Sub Page_Load()
If Not IsPostBack Then
fp = CType(Context.Handler, FirstPageClass)
End If
End Sub
</script>
</head>
<body>
<form runat="server">
Hello <%=fp.FirstName%> <%=fp.LastName%>
</form>
</body>
</html>

Wednesday, March 21, 2012

passing a GUID in the querystring

I need to pass a GUID into a page via the QueryString. If I do:

Dim myGUID as GUID
GUID = Request.QueryString("myGUID")

It won't run, and says that a value type of string cannot be converted to a GUID. I can't retype myGUID as a string, because I use it in a SQL Server Database call...It yells at me if try to do a query with it in there.

Am I doing something wrong? or is there just no way to pass a GUID through the querystring?

ThanksIf you pass the value on the url it will be in a string format. The following worked for me. Maybe this will help.

select * from table1 where uniqueID = cast('{5BEEAA61-394B-44F6-9AC8-A6EA5FC99490}' as uniqueidentifier)
You need to do the following:

Dim MyGuid As Guid = New Guid(Request.QueryString("myGuid"))

Friday, March 16, 2012

passing a variable to new page

Hello
I am new to asp.net, please help.
I have link and this works fine
Add/Edit

In classic asp I would use

<% Request.form("tbName ") %>

or
<% Request("tbName") %>

Sometimes I would assign this value to a variable and use it anywhere on the page.
How do I do this or is there a better way to do it in .net.
TIA MichaelIn the adim_sCodeEdit.aspx file, you just do the same:

(In the code behind file)

Dim tbName as string = request.params("tbName")

...
And do the test, make sure you capture the right result:

 response.write(tbName)

Thanks for the quick reply le9569
My companies isp does not support code behind.
This is how I have it now and it works. I was not sure where to put the
 response.write(tbName)
to make it work, everyplace I tried gave me errors.
Thanks again


<%@. Page Language="vb" Debug="true" %>
<script runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
Dim tbName as string = request.params("tbName")
lbltbName.text = tbName
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:Label id="lbltbName" runat="server"></asp:Label>
</form>
</body>
</html>