Link to home
Start Free TrialLog in
Avatar of REA_ANDREW
REA_ANDREWFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Link Button EventArgs

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
Avatar of REA_ANDREW
REA_ANDREW
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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
u can always call the custom function within the event handler

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

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

where is it getting the information for "CurrentLink" from?
   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.

:-)
try ..
Handle_Click(Object)
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?
ASKER CERTIFIED SOLUTION
Avatar of EtherZa
EtherZa

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent, worked a treat

:-)

Thankyou
Avatar of EtherZa
EtherZa

Glad to help :)
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
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
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
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?
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