VB.net 2005 & GridView & HyperLinkField & click event

Gang:

I am trying to click on a HLF in a GV; however, I am unable to capture the declaration/click event.

If I throw a test button on the page, the code behind for that click event fires off the code.

How do I capture the click event for the HLF in the GV? What declaration/event am I trying to capture?


A+ BS MCSE OOP Security+ Web Developer
Get creative, not even.
0
maniac
9/14/2006 7:25:13 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

5 Replies
700 Views

Similar Articles

[PageSpeed] 59

Hey,

You can't capture the click event for HyperlinkField; HyperLink controls don't have a click event.


Brian

"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
0
bmains
9/14/2006 7:57:27 PM

A+ BS MCSE OOP Security+ Web Developer
Get creative, not even.
0
maniac
9/14/2006 8:12:59 PM
You can try using a LinkButton, perhaps -- ?
-- Mike Pope

ASP.NET User Education

This posting is provided "AS IS" with no warranties, and confers no rights.

0
mikepope
9/14/2006 11:40:10 PM

Hey,

Yes, use a linkbutton, set the commandname to something like "navigate" and the commandargument to the url, and in the RowCommand event handler, do:

if (e.CommandName = "navigate")
{
    //Handle click with whatever you want to do

    Response.Redirect(e.CommandArgument.ToString(), false);
}


Brian

"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
0
bmains
9/15/2006 4:29:32 PM

Gang:

  • Thanx!
    • I ended up doing more research, along with trial & error.
  • On the .aspx page, I ... 
    • Changed the buttonfield in the GV to a templatefield which left a linkbutton.
    • Went to the end of the linkbutton field to see what would pop-up.
      • Lo & behold, MS Javascript was built-in.
        • Added onclick = "NAME OF DECLARATION ON CODE BEHIND PAGE".
    • This code passes in the name of the document on that row.
      • <asp:TemplateField AccessibleHeaderText="test" HeaderText="test" ShowHeader="False">
      • <ItemStyle CssClass="gvItem" />
      • <HeaderStyle CssClass="gvHeader" />
      • <ItemTemplate>
      • <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" commandName="ButtonClick" Text='<%# Eval("ControlNumber", "{0}") %>' OnClick="test"></asp:LinkButton>
      • </ItemTemplate>
      • </asp:TemplateField>
  • On the code behind, I used this declaration which was ...
    • Protected per MS recommendations
    • Removed 'Handles such & such' since it was causing BC30506 error (e.g. clause requires a WithEvents variable)
      • Basically, too much MS verbiage ...
        • Protected Sub test(ByVal sender As Object, ByVal e As System.EventArgs)
        • 'retrieve doc @ db
        • PUT  CLICK EVENT CODE HERE
        • End Sub
  • It's party time!
    • CYA
      • Devil

A+ BS MCSE OOP Security+ Web Developer
Get creative, not even.
0
maniac
9/15/2006 8:30:33 PM
Reply: