Hi
i started with WSP (website form) with Visual Studio and i have some little questions, compared with the classic Console project and OOP programming.
Thanks.
1)
public partial class MyClass_sel : System.Web.UI.Page
{
internal int tot=5;
//public int tot=5;
//protected int tot=5;
//private int tot=5;
private void Page_Load(object sender, EventArgs e)
{
Label1.Text = tot.ToString();
...
Every access modifiers works. Which one is best here?
How come that Page_Load is accessible here? It's private, so ...
-----------------------------------------
2)
public partial class MyClass_sel : System.Web.UI.Page
{
internal DropDownList dd;
internal SqlCommand comd;
internal string sql;
internal SqlDataReader dtreader;
protected void Page_Load(object sender, EventArgs e)
{
dd = DropDownList;
string m = "";
ListItem z;
using (SqlConnection mConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["myconnect"].ConnectionString))
{
mConnection.Open();
sql = "select distinct gem from leden";
comd = new SqlCommand(sql, mConnection);
dtreader = comd.ExecuteReader();
if (dtreader.HasRows)
{
while (dtreader.Read())
{
m = dtreader.GetString(0);
z = new ListItem(m);
dd.Items.Add(z);
}
}
dtreader.Close();
mConnection.Close();
}
}
private void Button1_Click(object sender, EventArgs e)
{
...
Line Button1_ClickObject is inaccessible due to protection level at line with { (just after if (dtreader.HasRows)). Why is that? Both methods are in the same class, so ...
----------------------------------------------------
3)
public partial class MyClass_sel : System.Web.UI.Page
{
public int tot;
public class Test
{
Label1.Text = tot.ToString();
}
...
The name Label1 (exists in aspx file) doesn't exist in current context. How can it be reached from a class?
------------------------------------------

Sachin SinghRank #66 · 26.2K reputationPosted Jul 21, 2021, 8:10 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jul 21, 2021, 6:59 AM EDT
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Jul 21, 2021, 7:18 AM EDT
Valerie MeunierRank #1,527 · 1K reputationPosted Jul 21, 2021, 7:52 AM EDT
{
Valerie MeunierRank #1,527 · 1K reputationPosted Jul 22, 2021, 1:11 PM EDT