i've been trying to call a method using javascript onclick(instead of running the code on page_load) to get the data i want to be printed on the page in the right places (in order for the user to edit his information) but i can't figure out how to do it with a static function. i haven't yet learned how to use non-static functions but when i removed the static part it allowed me to access my html tags, but the code ran regardless of whether i called the method or not.
HTML
<input type="button" onclick="<%GetUserData();%>"/>
Behind code : paymentOptions is the id of the select tag, notnow is the radio for not choosing a payment option, and payment is the radio for choosing a payment option, which then shows the select tag
static void GetUserData()
{
string sqlS = "select * from UserInfo where IDD='" + Session["UserId"] + "'and Pass='" + Session["UserPass"] + "'";
DalAccess dal = new DalAccess(sqlS);
ds = dal.GetDataSet(sqlS);
if (ds.Tables[0].Rows.Count == 1)
{
DataRow row = ds.Tables[0].Rows[0];
if (row["PaymentOptions"].ToString() == "NotNow")
{
notnow.Checked = true;
}
else
{
payment.Checked = true;
switch (row["PaymentOptions"].ToString())
{
case "option1": paymentOptions.SelectedIndex = 1;
break;
case "option2": paymentOptions.SelectedIndex = 2;
break;
case "option3": paymentOptions.SelectedIndex = 3;
break;
case "option4": paymentOptions.SelectedIndex = 4;
break;
case "option5": paymentOptions.SelectedIndex = 5;
break;
}
}
}
}
It gives me this error: an object reference is required for the nonstatic field method or property
Obviously, i understand what this means, but my question is: How do i access HTML tags in a static method?
您无法从ststic方法访问html,它们仅在实例上可用
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.