小编mon*_*ica的帖子

如何访问静态方法中的Asp控件?

ASP:代码

<asp:TextBox ID="TextBox1" runat="server" ReadOnly="true"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" ReadOnly="true"></asp:TextBox>
Run Code Online (Sandbox Code Playgroud)

C#:

[System.Web.Services.WebMethod]
public static Array LoadAssetAssignView() {
 string sql = "SELECT Time,Inuse FROM table4";
 using(SqlConnection Connection = new SqlConnection((@ "Data Source"))) {
  using(SqlCommand myCommand = new SqlCommand(sql, Connection)) {
   Connection.Open();
   using(SqlDataReader myReader = myCommand.ExecuteReader()) {
    DataTable dt = new DataTable();
    dt.Load(myReader);
    Connection.Close();
    Num1 = textbox1.text; //Error(Can't access my asp control)
    Num2 = textbox2.text;
   }
  }
 }
}
Run Code Online (Sandbox Code Playgroud)

在我的Asp页面我涉及两个文本框我的要求.但在我的后端,我无法访问静态方法中的文本框.建议一些想法.答案而不是评论被赞赏.

c# asp.net

1
推荐指数
1
解决办法
5056
查看次数

标签 统计

asp.net ×1

c# ×1