Column button to edit a record without going thru postback?

R

Randall Parker

Currently in an asp:DataGrid I have a column for bringing up an edit form on a
particular row and that is done by a hyperlink as follows:

<asp:TemplateColumn HeaderText="Edit Record">
<ItemTemplate>
<asp:HyperLink id="hyperlink1"
NavigateUrl='<%# "EquipmentEdit.aspx?serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num") %>'
Text='Edit'
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>

Instead of a text hyperlink I'd like a button appearance on that cell on each row so
that the reader can see more clearly that clicking on it carries out an action. I
figure there are two ways to do that:

1) Make a button that does a submit and then have the CommandArgument carry both the
action and the record id to use to open a different form. Then recognize in the
Page_Load (or in some more appropriate server-side event?) that there is a postback
and then look at the CommandArgument to parse out the action and the record id. Then
to a Response.Redirect to that form with that argument.

2) Make the button on the client form have an event to directly go to the destination
page. I'm an ASP.Net novice and it is not clear to me how to do this.
A) Is there an asp button control that is made for this purpose where one can
give it a URL just as one can with the asp:HyperLink? If so, which control?
B) Otherwise, which asp button control to use and do I just write a Javascript
myself inside the <script> </script> tag? If so, how to get the string built up in
the asp button control to pass to the Javascript to build the URL? I figure Ineed the
DataBinder.Eval but am not clear where I'd use it in this case.
 
S

Sanjeevakumar Hiremath

Try this out. for the option A in the 2nd possibility.. Hope it is helpful.


<asp:TemplateColumn HeaderText="Edit Record">
<ItemTemplate>
<INPUT type="button" value="Edit" onClick="window.open('<%#
"EquipmentEdit.aspx?serial=" + DataBinder.Eval(Container, "DataItem.ID")
%>','mywindow','width=400,height=200')">
</ItemTemplate>
</asp:TemplateColumn>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top