0

I have Img tag on form and I want to send the id of this to aspx.cs . I used post method and retriving this id using Request.Form["id"] but i'm not getting id on aspx.cs file .

code:

$("img").click(function () {
 var id = $(this).attr("id");// Here I am getting id How can i send this id to aspx.cs
 jq.post("WebForm1.aspx",
             id: $(this).attr("id"));
});
gdoron
  • 147,333
  • 58
  • 291
  • 367
sanjay
  • 1
  • 1
  • Don't over use jQuery. `this.id` will bring you the `id` easier and a lot faster than `$(this).attr('id')` – gdoron May 03 '12 at 07:24

3 Answers3

0
$("img").click(function () {
        var id = $(this).attr("id");// Here I am getting id How can i send this id to aspx.cs
        //alert(id); 
        jq.post("WebForm1.aspx", id: id);//this is enough
    });
Ankur Verma
  • 5,793
  • 12
  • 57
  • 93
  • Actually I can't see what did you fix in this answer? you just use the same value like he did. – gdoron May 03 '12 at 07:39
0

There may be an issue with this getting over-written when you open the post method. Try:

$("img").click(function () {
      var my_id = $(this).attr("id");
      $.post("WebForm1.aspx", { id: my_id });
});

Alternatively, if you have several parameters to pass to the form, you could build your object ahead of time, like so:

$("img").click(function () {
      var params = {id: $(this).attr("id"), href: $(this).attr("href")};
      $.post("WebForm1.aspx", params);
});
Anthony
  • 36,459
  • 25
  • 97
  • 163
0
$("img").click(function () {
        var id = this.id; // No jquery needed!
        jq.post("WebForm1.aspx", {id: id});
    });

Don't over use jQuery. this.id will bring you the id easier and a lot faster than $(this).attr('id')

gdoron
  • 147,333
  • 58
  • 291
  • 367