Hi
I have the following code and why can't i change the value of myvar in the
DataGrid1_editcommand event so that the (changed) value of myvar is there in
the Update event?? (it fires i debugged it!):
namespace MYproject
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class MyUsercontrol: System.Web.UI.UserControl
{
public string myvar ="hello";
private void Page_Load(object sender, System.EventArgs e)
{
}
public void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
myvar ="goodbye"; //enters this code first
}
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string temp; // enters this code next!!!
temp = myvar; // myvar = "hello" ???? instead of the wanted "goodbye"
}
}
}
ch Tom 3 976
The variable value will be lost between postbacks. If it need to be
persisted it should be saved to teh view state by the control and got back
when a postback occurs.
Ciaran
"Tom" <to**********@hotmail.com> wrote in message
news:eK**************@TK2MSFTNGP10.phx.gbl... Hi
I have the following code and why can't i change the value of myvar in the DataGrid1_editcommand event so that the (changed) value of myvar is there in the Update event?? (it fires i debugged it!):
namespace MYproject
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; public class MyUsercontrol: System.Web.UI.UserControl
{
public string myvar ="hello"; private void Page_Load(object sender, System.EventArgs e)
{
}
public void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
myvar ="goodbye"; //enters this code first
} private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string temp; // enters this code next!!!
temp = myvar; // myvar = "hello" ???? instead of the wanted "goodbye"
}
}
}
ch Tom
so how do you code all this? do you have a sample for this?
"Ciaran" <ci****@theodonnells.plus.com> wrote in message
news:41***********************@ptn-nntp-reader04.plus.net... The variable value will be lost between postbacks. If it need to be persisted it should be saved to teh view state by the control and got back when a postback occurs.
Ciaran
"Tom" <to**********@hotmail.com> wrote in message news:eK**************@TK2MSFTNGP10.phx.gbl... Hi
I have the following code and why can't i change the value of myvar in
the DataGrid1_editcommand event so that the (changed) value of myvar is
there in the Update event?? (it fires i debugged it!):
namespace MYproject
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; public class MyUsercontrol: System.Web.UI.UserControl
{
public string myvar ="hello"; private void Page_Load(object sender, System.EventArgs e)
{
}
public void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
myvar ="goodbye"; //enters this code first
} private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string temp; // enters this code next!!!
temp = myvar; // myvar = "hello" ???? instead of the wanted "goodbye"
}
}
}
ch Tom
Hi,
You could simply save it in a session as
Session("myvar") = myvar;
later you retrieve it using
myvar = Session("myvar").ToString();
Please note that you should make sure that you saved the variable before
retrieve , usually you do so in the onload event checking for the IsPostBack
property.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Tom" <to**********@hotmail.com> wrote in message
news:Og**************@TK2MSFTNGP12.phx.gbl... so how do you code all this? do you have a sample for this? "Ciaran" <ci****@theodonnells.plus.com> wrote in message news:41***********************@ptn-nntp-reader04.plus.net... The variable value will be lost between postbacks. If it need to be persisted it should be saved to teh view state by the control and got back when a postback occurs.
Ciaran
"Tom" <to**********@hotmail.com> wrote in message news:eK**************@TK2MSFTNGP10.phx.gbl... > Hi > > I have the following code and why can't i change the value of myvar in the > DataGrid1_editcommand event so that the (changed) value of myvar is there > in > the Update event?? (it fires i debugged it!): > > namespace MYproject > > { > > using System; > > using System.Data; > > using System.Drawing; > > using System.Web; > > using System.Web.UI.WebControls; > > using System.Web.UI.HtmlControls; > > > > public class MyUsercontrol: System.Web.UI.UserControl > > { > > public string myvar ="hello"; > > > > private void Page_Load(object sender, System.EventArgs e) > > { > > > } > > > public void DataGrid1_EditCommand(object source, > System.Web.UI.WebControls.DataGridCommandEventArgs e) > > { > > > myvar ="goodbye"; //enters this code first > > > } > > > > private void DataGrid1_UpdateCommand(object source, > System.Web.UI.WebControls.DataGridCommandEventArgs e) > > { > > string temp; // enters this code next!!! > > temp = myvar; // myvar = "hello" ???? instead of the wanted "goodbye" > > > } > > } > > } > > ch Tom > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: manish |
last post by:
I have created a function, it gives more readability compared to the
print_r function. As of print_r, it works both for array or single
variable. I just want to add in it, the opton to view the...
|
by: James A. Donald |
last post by:
I am contemplating getting into Python, which is used by engineers I
admire - google and Bram Cohen, but was horrified to read
"no variable or argument declarations are necessary."
Surely that...
|
by: Graham |
last post by:
This has to do with class variables and instances variables.
Given the following:
<code>
class _class:
var = 0
#rest of the class
|
by: Gery D. Dorazio |
last post by:
Gurus,
If a static variable is defined in a class what is the scope of the variable
resolved to for it to remain 'static'? For instance, lets say I create a
class library assembly that is...
|
by: Maarten |
last post by:
Here is a nice problem. I have two scripts, one calling the other with via
an include. The script that is included contains a variable, a function and
a call to that function. The variable needs to...
| |
by: pbmods |
last post by:
VARIABLE SCOPE IN JAVASCRIPT
LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN )
PREREQS: VARIABLES
First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
|
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= |
last post by:
Hi,
When I try to compile the below code snippet, I get the compile error listed
below in this question. In the lines below the loop, the variable j does not
excist, however, trying to create it...
|
by: somenath |
last post by:
Hi All ,
I have one question regarding scope and lifetime of variable.
#include <stdio.h>
int main(int argc, char *argv)
{
int *intp = NULL;
char *sptr = NULL;
|
by: istillshine |
last post by:
When I control if I print messages, I usually use a global variable
"int silent". When I set "-silent" flag in my command line
parameters, I set silent = 1 in my main.c.
I have many functions...
|
by: SRoubtsov |
last post by:
Dear all,
Do you know whether ANSI C (or some other dialects) support the
following:
* a variable name coincides with a type name,
* a structure/union field name coincides with a type name
in...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |