views:

253

answers:

2

Hi!

I have a ASP.NET Website, where, in a GridView item template, automatically populated by a LinqDataSource, there is a LinkButton defined as follows:

<asp:LinkButton ID="RemoveLinkButton" runat="server" CommandName="Remove"
                CommandArgument='<%# DataBinder.GetPropertyValue(GetDataItem(), "Id")%>'                                 
                OnCommand="removeVeto_OnClick"
                OnClientClick='return confirm("Are you sure?");'
                Text="Remove Entry" />

This works fine. Whenever the Button is Clicked, a confirmation dialog is displayed.

What I am trying to do now, is to allow the user to enter a reason for the removal, and pass this on the the OnClick event handler. How would I do this? I tried OnClientClick='return prompt("Enter your reason!");', but, of course, that did not work =)

+2  A: 

Personally, I would stash the reason into a hidden field.

It would work something along these lines: your OnClientClick method would take the return value of a JS method, which does the prompt, and then places the result of the prompt into the hidden field.

Stephen Wrighton
+1  A: 

You can also look into calling __doPostBack from your client-side code instead of using the OnClick postback. Then you can capture the reason and pass it server-side.

Tim
Is there a simple method to extract the rather weird ID 'ctl00$ContentPlaceHolder1$GridView1$ctl02$RemoveLinkButton' used in the autogenerated __doPostBack call using javascript? I guess I'd need that...
Jens
There sure is. Use '#<%=ControlName.ClientID %>' where ControlName is the name of the control whose ID you need. You could also pass the ID to your javascript function as a parameter in your OnClientClick call in your GridView. That actually might be the easier method since you're using the GridView.
Tim