Resolved How does Page_Load work

Solstice

New member
Joined
Apr 1, 2022
Messages
4
Programming Experience
3-5
I am New to C#. This program loads the data in Page_Load correctly. When you click on the button even after I change the data in the textboxs
the Page_Load still fires and reloads the current data from the DateTime. Is there another thing in C# that just loads on startup and not when the Button is pressed?


protected void Page_Load(object sender, EventArgs e)
{
DateTime current = DateTime.Now;
tbmo.Text = current.Month.ToString();
tbdy.Text = current.Day.ToString();
tbyr.Text = current.Year.ToString();
tbhr.Text = current.Hour.ToString();
tbmn.Text = current.Minute.ToString();
tbsc.Text = current.Second.ToString();
tblon.Text = "-81.5";
tblat.Text = "40.8";
}
protected void BtnPlanets_Click(object sender, EventArgs e)
{
double mo, dy, yr, tz, lon, hr, mn, sc, dst, lat, ut, m1, y1, Bjd, JD0, JD, J, d, LMST, GMST;
double Pi = Math.PI;
//int k;
mo = Convert.ToDouble(tbmo.Text);
dy = Convert.ToDouble(tbdy.Text);
yr = Convert.ToDouble(tbyr.Text);
lon = Convert.ToDouble(tblon.Text);
hr = Convert.ToDouble(tbhr.Text);
mn = Convert.ToDouble(tbmn.Text);
sc = Convert.ToDouble(tbsc.Text);
lat = Convert.ToDouble(tblat.Text);
}
 
I've hardly used Web Forms and not at all for a long time but, if I remember correctly, you're supposed to test the IsPostBack property to determine whether the event was raised by the initial load or a postback. The documentation for that property has a simple example.
 
Solution
Back
Top Bottom