Question How to post from a gridview

dolot

New member
Joined
Jul 3, 2013
Messages
4
Programming Experience
10+
I have a situation where I have a group of records displayed on a page using a gridview. I want the user to be able to click on a record and have the browser navigate to another page where I display the details associated with the record. I have figured out how to do this using a hyperlink column on the grid. This works great, except for one thing: The key information is passed to the server in the querystring, which is something we'd like to avoid. Is there a way to have a column with a button or something that does an http post, so that the key information is hidden?

Any tips would be helpful. I'm new to this web world, so if I'm using a wrong paradigm or something feel free to speak up.
 

dolot

New member
Joined
Jul 3, 2013
Messages
4
Programming Experience
10+
That all sounds plausable, but I'm lost as to how to implement it. Here's a snippet of code representing one of the rows in the datatable.
Code:
[COLOR=#0000ff]</[/COLOR][COLOR=#800000]tr[/COLOR][COLOR=#0000ff]>[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]tr[/COLOR][COLOR=#ff0000]style[/COLOR][COLOR=#0000ff]="background-color:#EFF3FB;">[/COLOR]
[COLOR=#0000ff]<[/COLOR][COLOR=#800000]td[/COLOR][COLOR=#0000ff]>[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]a[/COLOR][COLOR=#ff0000]href[/COLOR][COLOR=#0000ff]="Ammo.aspx?Item=2">[/COLOR]A011[COLOR=#0000ff]</[/COLOR][COLOR=#800000]a[/COLOR][COLOR=#0000ff]>[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]td[/COLOR][COLOR=#0000ff]>[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]td[/COLOR][COLOR=#0000ff]>[/COLOR]1305000963158[COLOR=#0000ff]</[/COLOR][COLOR=#800000]td[/COLOR][COLOR=#0000ff]>[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]td[/COLOR][COLOR=#0000ff]>[/COLOR]
[COLOR=#0000ff]<[/COLOR][COLOR=#800000]input[/COLOR][COLOR=#ff0000]type[/COLOR][COLOR=#0000ff]="submit" [/COLOR][COLOR=#ff0000]name[/COLOR][COLOR=#0000ff]="ctl00$MainContent$GridView3$ctl02$Button1" [/COLOR][COLOR=#ff0000]value[/COLOR][COLOR=#0000ff]="..." [/COLOR][COLOR=#ff0000]onclick[/COLOR][COLOR=#0000ff]="Navigate();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$GridView3$ctl02$Button1", "", false, "", "Ammo.aspx", false, false))" [/COLOR][COLOR=#ff0000]id[/COLOR][COLOR=#0000ff]="MainContent_GridView3_Button1_0" />[/COLOR]
[COLOR=#0000ff]</[/COLOR][COLOR=#800000]td[/COLOR][COLOR=#0000ff]>[/COLOR]
[COLOR=#0000ff]</[/COLOR][COLOR=#800000]tr>[/COLOR]
I was able to figure out how to add a javascript function to the button to respond to the click event. A couple of things, though, have me puzzled.

1. How can I determine the ID value based upon the button that is clicked? In other words, how can I reference the row in the table that contains the button that was clicked, and from this fish out the cell that contains the value for the ID.

2. The form information is autogenerated by the .net framework, so how can I add a hidden field to this form for submittal back to the server?
 

dolot

New member
Joined
Jul 3, 2013
Messages
4
Programming Experience
10+
Well thank you for taking the time to let me know that. It's certainly better than just being ignored. :)
 

nayanpatel

Active member
Joined
Nov 18, 2016
Messages
27
Location
ahmedabad
Programming Experience
3-5
Just pass the input element ID in onclick() event like this:

<input type="submit" name="ctl00$MainContent$GridView3$ctl02$Button1" value="..." onclick="navigate(this.id)" id="..."/>

or you can pass element itself :

<input type="submit" name="ctl00$MainContent$GridView3$ctl02$Button1" value="..." onclick="navigate(this)" id="..."/>
 

dolot

New member
Joined
Jul 3, 2013
Messages
4
Programming Experience
10+
Thanks for taking the time there, Nayan. This thread is pretty old, though, and since creating this thread I've learned how to do this. :)
 
Top Bottom