Hi,
I have this C#/ASP.NET .aspx page.
I have the following relevant code at the beginning:
<script runat="server">
public string ID="";
protected override void OnLoad(EventArgs e) {
ID= "Mario"; // ID must be set here
(...)
}
</script>
After this, I have a form.
But in the end of the page, I need to know the ID value.
Problem is I get the error "The name 'ID' does not exist in the current context".
Does anyone know how can I get it ?
Any help would be appreciated.
Warm Regards,
Mário Gamito
ASKER
Thank you for your answer.
The ID comes from the following SELECT on a MS SQL SERVER as shown.
It works just right, but I can't access its value outside this part of the code:
<script runat="server">
protected override void OnLoad(EventArgs e) {
int ID = -1;
SqlConnection myConn = new SqlConnection("Data Source=192.168.1.50"; Initial Catalog=mydb; User=123; Password=123");
try
{
myConn.Open();
SqlCommand myCommand = new SqlCommand("SELECT MAX(PostID) from dbo.Posts", myConn);
ID = (int)myCommand.ExecuteScal
}
finally
{
if (myConn != null)
{
myConn.Close();
}
}
}
</script>
Warm Regards,
Mário Gamito