Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing values between events of unlike signature

Status
Not open for further replies.

jasonsalas

IS-IT--Management
Jun 20, 2001
480
GU
Hi everyone,

Got a new one: I'm trying to evaluate the contents of one event and pass this information on to a subsequent method, but it's coming out funny. Basically I have a DataGrid that allows a user to display his personal buddy list or a public list, accesible to everyone, or a company-only list.

He can toggle between the two using LinkButton controls on the page. When a user clicks on whichever view to see, I assign a flag in ViewState to keep track of what view he's currently on. Editing mode is enabled for the DataGrid, but when I enter edit Edit mode, it doesn't have the right set of data (the right specific record), implying wrong command arguments being passed in.

Here's the event handler I'm using:

public void Edit_Contacts(object sender, DataGridCommandEventArgs e)
{
// get the specific record you need to enter edit mode for...
dgContacts.EditItemIndex = e.Item.ItemIndex;

// ...and display that record's data
string mode = (string)ViewState["viewMode"];
if(mode != null)
{
switch(mode)
{
case "PRIVATE":
GetMyList(this,e);
break;
case "ALL":
GetAll(this,e);
break;
case "NTERNAL":
GetInternal(this,e);
break;
}
}
}

However, the events specified in the Switch statement all have argument lists that are of type CommandEventArgs, so the signatures are inconsistent (the first event handler is of type DataGridCommandEventArgs):

// example...they're all like this
protected void GetAll(object sender, CommandEventArgs e)

I tried casting the arguments in e to the destination type of CommandEventArgs, but no dice. Got any ideas?

Thanks!
Jas
 
You have your 'this' operator a little mixed up, as it's referring to the current instance of the class that you're in (i.e. you're sending the page class to getAll when you call it like that). It would look like this:

getAll(sender,e);

And, you're not going to be able to cast those event arguments like that, either. :-(

If I wish to pass off some of my handling, then I'll normally just write another method that only accepts the event args and just handle it that way. Besides, I've yet to even use the sender argument to an event handler.

private void getAll(DataGridCommandEventArgs e){
//process, process
}

Is there some reason you would need the sender in your getAll method, or some other reason why this method wouldn't work for you?

-paul
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Good point...I didn't consider that. I do know that I'm making calls to GetAll(this,e) in other places in the code, but I'll try modifying those.

Thanks!
 
Hi,

I was actually able to get away with it by using "null" as the argument instead of passing "e":

string mode = (string)ViewState["viewMode"];
if(mode != null)
{
switch(mode)
{
case "PRIVATE":
GetMyList(this,null);
break;
case "ALL":
GetAll(this,null);
break;
case "INTERNAL":
GetInternal(this,null);
break;
}

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top