Swaroop Kumar
Swaroop Kumar

Reputation: 1

how can i access variables that are defined in a jquery in to aspx page

i am working as a dotnet trainee and i am working on image mapping tool so when i select some portion on an image the coordinates should be read and saved in hidden fields.I am using a Jquery for mapping and i have to access the variables that are defined in that jquery in to aspx page.Is it possible to do so if possible please suggest me how to achieve this.

Thanking You, swaroop

Upvotes: 0

Views: 163

Answers (4)

Sergey
Sergey

Reputation: 8071

I think the best approach to not use hidden fields for this. If you suppose to use more than one pair x;y, then you need to save it in array with javascript. After that you can send it to server (if it is needed) with ajax.

Array points = new Array();
points[0].x = 10;
points[0].y = 20;

Also you can add this collection to form method (if it is needed).

Upvotes: 0

reshma k
reshma k

Reputation: 544

If you are saving those coordinates in hidden fields (i.e. asp.net's hiddenfield controls) ,you can directly access those fields in .aspx.cs file.

as

int xCoordinate = Convert.toInt32(hidden1.value);

and in js file you can assign value to hidden field as

  $("[id$='_hiddenfieldID']").val("1");

is this is what u required?

Upvotes: 0

satin
satin

Reputation: 707

if by aspx page you mean in the backend code then you need to supply those variables through ajax because static page fields won't change , we just manipulate them on user side with jquery. otherwise if it's on user side only, then just use the method given by Adam

Upvotes: 0

Adam Tuliper
Adam Tuliper

Reputation: 30152

Im assuming you mean when you read the coordinates you want to write to some hidden fields. Do you need more than one field for each coordinate? Can you store multiple sets of coordinates? In its basic form, you can simply set the info as:


$("#xPosition").val("123");
$("#yPosition").val("456");

//access them:
var y = $("#yPosition").val();

This is assuming you have two hidden fields defined on the page. Is this what you are looking for or did I misunderstand the question?

Upvotes: 1

Related Questions