passing a value from one method to another method without calling the method, infact no relation exists between two methods, just value is needed.
-
Hi, i have a senario, 3 buttons and 2 gridviews.The buttons(three buttons) related to the information in first Gridview is clicked, it populates the second gridview with the corresponding table in database. Now my_method needs to know which button is clicked, so that it uses stored procedure to do some database operations on that particular table. Is there any way to get the value from button_clicked() to my_method, without calling my_method. The value will be used only when my_method() is called by some other operation. Thanks
-
Hi, i have a senario, 3 buttons and 2 gridviews.The buttons(three buttons) related to the information in first Gridview is clicked, it populates the second gridview with the corresponding table in database. Now my_method needs to know which button is clicked, so that it uses stored procedure to do some database operations on that particular table. Is there any way to get the value from button_clicked() to my_method, without calling my_method. The value will be used only when my_method() is called by some other operation. Thanks
You could store the information in a field on the class in which the method resides.
Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual
-
Hi, i have a senario, 3 buttons and 2 gridviews.The buttons(three buttons) related to the information in first Gridview is clicked, it populates the second gridview with the corresponding table in database. Now my_method needs to know which button is clicked, so that it uses stored procedure to do some database operations on that particular table. Is there any way to get the value from button_clicked() to my_method, without calling my_method. The value will be used only when my_method() is called by some other operation. Thanks
sounds like you want to use a delegate.
Christian Graus Driven to the arms of OSX by Vista.
-
sounds like you want to use a delegate.
Christian Graus Driven to the arms of OSX by Vista.
You're starting to sound like "Clippy".
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
You could store the information in a field on the class in which the method resides.
Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual
Hi, class { protected void Button1_Click(object sender, EventArgs e) { resbutton = "abcMenu"; ..... } protected void Button2_Click(object sender, EventArgs e) { resbutton = "defMenu"; ..... } protected void Button3_Click(object sender, EventArgs e) { resbutton = "jklMenu"; ..... } protected void Button4_Click(object sender, EventArgs e) { resbutton; // here i need the value of resbutton for different above button_click events ..... } } fields are not working properly. can u provide me some related code. Thanks
-
Hi, class { protected void Button1_Click(object sender, EventArgs e) { resbutton = "abcMenu"; ..... } protected void Button2_Click(object sender, EventArgs e) { resbutton = "defMenu"; ..... } protected void Button3_Click(object sender, EventArgs e) { resbutton = "jklMenu"; ..... } protected void Button4_Click(object sender, EventArgs e) { resbutton; // here i need the value of resbutton for different above button_click events ..... } } fields are not working properly. can u provide me some related code. Thanks
suni_dotnet wrote:
fields are not working properly.
I don't see any evidence from this code that you have a field at all. Here is your code re-written:
class MyForm
{
private string resbutton; // This is the fieldprotected void Button1_Click(object sender, EventArgs e)
{
resbutton = "abcMenu";
// .....
}protected void Button2_Click(object sender, EventArgs e)
{
resbutton = "defMenu";
// .....
}protected void Button3_Click(object sender, EventArgs e)
{
resbutton = "jklMenu";
// .....
}protected void Button4_Click(object sender, EventArgs e)
{
switch(resbutton)
{
case "abcMenu":
// Do stuff based on Button1 being pressed
break;
case "defMenu":
// Do stuff based on Button2 being pressed
break;
case "jklMenu":
// Do stuff based on Button3 being pressed
break;
default:
// Do suff based on none of the buttons being pressed
break;
}
}
}Of course there may be better ways of doing this, but since we don't know what your actual overall goal is we can't say. Christian's suggestion of using delegates has merit also. I'd also suggest using something other than a string for the field. Creating a specific enum that enumerates each type of button would be good.
Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual