473,327 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Newbie question on postback event and Page Load

2
Hi all,

I'm just a begginer, and i have a simple question here:

I'm using C#, asp.net..

How can I save data from fields that I declare in Page class, after pressing a button, and of course, as a postback event occurs. for example:

public partial class myPage : System.Web.UI.Page
{
private int cnt;
.... ... ...
}
I want to save value in cnt and have it there whene Page loads again...?
Any directions which classes handle that, or sth??

Thanks
Dec 25 '06 #1
6 1489
yohney
2
Just to add, best thing I can remember is to create a Label, set it label.Visible=false, and write data which i need to send... sad...
Dec 25 '06 #2
Frinavale
9,735 Expert Mod 8TB
Hi all,

I'm just a begginer, and i have a simple question here:

I'm using C#, asp.net..

How can I save data from fields that I declare in Page class, after pressing a button, and of course, as a postback event occurs. for example:

public partial class myPage : System.Web.UI.Page
{
private int cnt;
.... ... ...
}
I want to save value in cnt and have it there whene Page loads again...?
Any directions which classes handle that, or sth??

Thanks
One way this could be accomplished is by using Session variables.
So if the user clicks a button to submit the form...in the function that handles that button click you would put something like:
Session("cnt")=cnt;
When you want to use this variable later you just retrieve it from the session like during postback you'd do something like:
cnt=(int)Session("cnt");

I'm not 100% on how its done in C#.

You should to look up Session variables for yourself.

Cheers!
-F
Dec 28 '06 #3
Hi Yohney,

Frinavale is right. You can use session. But first you must get the name from a textbox or any other input, and put it in the session variable.

example:

session ["myVariable"] = someValue.Text; //if u grab from an input
or
session ["myVariable"] = "someValue"; //to assign your own session

when page loads
if (page != IsPostBack)
outPutLabel.Text = (string)Session["myVariable"];

Hope this helps.

Cheers!
Dec 29 '06 #4
karthi84
271 100+
hi all there,
is there any other method to carry a value to other page or the same page without using session. if my question is silly i am sorry.
Dec 30 '06 #5
nmsreddi
366 256MB
hi kartheek

for sending value of variable from one page to another you can use query string

response.redirect(?val= ""&"destination form name")

no need of going for sessions unless you want to use the variable through out your

application


regards

Nmsreddy
Jan 1 '07 #6
karthi84
271 100+
thanks nmsreddi,


your reply helped me a lot.
Jan 2 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Matthew Louden | last post by:
I created simple ASP.NET web application to test how AutoPostBack property in a web control works. I set AutoPostBack property to be true of a web control. When I run the application, here's the...
2
by: Earl Teigrob | last post by:
I have run into a situation where I need to run the !IsPostBack code under one circumstance, even if it is a postback. Something that may complicate matters more is that this is a double postback...
1
by: Marcel Balcarek | last post by:
I create a user control dynamically: Dim newCriteriaControl As CriteriaTextBoxUserControl = CType(Me._page.LoadControl("CriteriaTextBoxUserControl.ascx"), CriteriaTextBoxUserControl) ...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
8
by: Chris Kennedy | last post by:
I want to click a button and have it does something before the page reloads. I now realize the page processes the server side event after page loads. Is there any way of triggering the postback...
0
by: Managed Code | last post by:
Hello All, Here is my issue and thanks in advance for any assistance. I have a base page with a dropdownlist that fires an event with the selected index. The content page catches the event and...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
7
by: =?Utf-8?B?TWlrZSBMb2dhbg==?= | last post by:
My environment. .Net 2.0 VS2k5 SP1, IE6 (6.0.2900.2180) I have a web content page. The page will post back twice if I am running in debug mode. However if I run through the breakpoints fast...
8
by: Mel | last post by:
I have several text boxes and drop-down lists in an AJAX Update Panel. All user inputs have the Postback property set to True. After I type something in the first input entry and press the "Tab"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.