?
Solved

Link Button EventArgs

Posted on 2006-06-01
14
Medium Priority
?
2,217 Views
Last Modified: 2012-06-21
Hi,

It might be me but I am unable to find the EventArgs for a LinkButton or a Hyperlink. i.e. Say I have this function

    protected void Clicked_Button(object sender, EventArgs e)
    {
        Response.Write(e.ID.ToString())
    }

The above is not possible cause the e does not contian this information and

    protected void Clicked_Button(object sender, LinkButtonEventArgs e)
    {
        Response.Write(e.ID.ToString())
    }

 LinkButtonEventArgs does not work cause it does not exist, i.e. so what I need is this.  I have that function above which is called by dynamic links. I need to be able to read information about which link was pressed via the EventArgs, but I do not know how to do this with the LinkButton or the ASP HyperLink

Thanks In advance

Andrew
0
Comment
Question by:REA_ANDREW
  • 6
  • 5
  • 3
14 Comments
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 16805997
TO EXPLAIN MY SELF MORE CLEARLY

Or to put it another way, how do I use this method of coding??

CurrentLink.Click += new EventHandler(CurrentLink_Click);

you see now writing this automatically produces this event

    void CurrentLink_Click(Object sender, EventArgs e)
    {
        throw new Exception("The method or operation is not implemented.");
       
    }

But I need to be able to write the event handler so I can use a custom function which I can pass variables into.  The below example does not work

CurrentLink.Click += new EventHandler(CurrentLink_Click(CurrentLink));

    void CurrentLink_Click(LinkButton e)
    {

        Response.Write(e.ID.ToString());
    }

THank you
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16806222
u can always call the custom function within the event handler

void CurrentLink_Click(Object sender, EventArgs e)
    {
       MyCurrentLink_Click(CurrentLink));
    }
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 16806232
using this though

void CurrentLink_Click(Object sender, EventArgs e)
    {
       MyCurrentLink_Click(CurrentLink));
    }

where is it getting the information for "CurrentLink" from?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 20

Author Comment

by:REA_ANDREW
ID: 16806251
   void CurrentLink_Click(object sender, EventArgs e)
    {
        Handle_Click(CurrentLink);//..........<-----CurrentLink is unreachable from here
    }
    protected void Handle_Click(LinkButton e)
    {
           
    }

So I cannot use that function as the LinkButton CurrentLink is unreachable and therefore I am unable to pass it as an argument into HandleCLick().

Thanks for the help so far.

:-)
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16806271
try ..
Handle_Click(Object)
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 16806287
Handle_Click(Object) <--------

would this not mean I would be passing an Object as the arument then and not a LinkButton?

i.e. the same would be true if I where to use sender, as this is the instance of the Object Object

that right?
0
 
LVL 3

Accepted Solution

by:
EtherZa earned 2000 total points
ID: 16806367
The sender is the object which fired the event. As such it can be cast back into the object type - see the example below:

protected void Clicked_Button(object sender, LinkButtonEventArgs e)
 {
   if (sender is WebControl)
  {
    // object is of type WebContol

    string id = (WebControl)sender;  // generic get id
    ...

   // you can also replace WebControl with LinkButton/Hyperlink to cast the object as that specific type. (LinkButton and HyperLink are both sub classes of the WebControl type)
  }
 }
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 16806402
Excellent, worked a treat

:-)

Thankyou
0
 
LVL 3

Expert Comment

by:EtherZa
ID: 16806431
Glad to help :)
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16840286
REA_ANDREW,
This is not fair .. i answered ur question and was just not fast enough to comment on ur last question
>>would this not mean I would be passing an Object as the arument then and not a LinkButton?

I would have still understood a spilt between my comments and the last comment by EtherZa. EtherZa just elaborated on what i had already said ..

Rejo
0
 
LVL 3

Expert Comment

by:EtherZa
ID: 16840410
Didn't want to create any ill feelings :(

Saw the post late; knew the answer and skimmed through the responses to see that it hadn't been answered. Will accept any resolution that admin gives.

EtherZa
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16840474
no ill feelings Etherza .. I do not think u did anything wrong by answering the question .. what I was not happy about is the way the question was closed .. infact i did notice the last questin that he had asked but by the time i had seen it u had already commented and i did not see any point in repeating the same thing or saying that you were right .. if u look at the thread u will notice that it took a couple of post to actually understand his requirements ..

Rejo
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 16840514
Rejojohny

My Apologies,  I Will post a request to the admins to split these points, ALTHOUGH.

I will assign 150 to you and 350 to EtherZa , reason being that yes you informed me to try and use Object but that was not right, and also at no point did you indicate I had to cast the Sender Argument, which would then hold the information I needed.  

EtherZa, hit the nail on the head, and solved it. I indicated that this was 500pts because it was urgent.  EtherZa supplied me with a working answer you did not on this occasion.

I agree that I awarded the points hastily, so no hard feelings lad! :-)

Andrew

P.S. Which section do I go to, to get this turned around?
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16840844
no problem .. i was a bit hasty in answering too .. what i meant was
Handle_Click(Sender) and not Handle_Click(Object) .. have been working too long on vb where the variable names comes on the right :-) .. anyway and no hard feeling ..

Rejo
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question