簡體   English   中英

為什么我無法訪問 Web 控件的功能?

[英]why can't i access a function of a web control?

我有下一個問題:

我有一個包含很多 Web 控件的 .aspx,這是我關心的:

//line 5
<%@ Register src="Controls/UCAttachments.ascx" tagname="UCAttachments" tagprefix="uc1" %>
//line 430
<uc1:UCAttachments ID="UCAttachments" runat="server" Visible="false" />  

在組合框的選定索引更改事件上,我需要調用 Web 控件的函數,這是 .aspx.cs 的代碼。

private void cbo_SelectedIndexChanged( object sender, EventArgs e )
{
 if(this.op == 1){
 UCAttachments.visible=true;
 UCAttachments.loadById(this.id); <-this doesnt work.
//Even tho, i can access all the other functions of UCAttachments.
//More infor abkout the error:
//'CONTROL' does not contain a definition for 'loadById'and no accessible //method accepting first argument...

 }
}
public partial class Controls_UCAttachments: System.Web.UI.UserControl
{
//lots of functions
  public void loadById( string id )
  {
    string query = "SELECT * FROM table WHERE ID = " +id;
    //more code
    return ;

  }
}

你必須使這個方法靜態

public partial class Controls_UCAttachments 
{
    //lots of functions
    static public void loadById(string id)
    {
        string query = "SELECT * FROM table WHERE ID = " + id;
        //more code
        return;

    }
}

您可以使用此語法調用

Controls_UCAttachments.loadById(this.id);

所以..非常好奇的事情。

當您有一個包含大量用戶控件的表單時,您需要等待元數據文件重新加載您創建的新方法。

所以我關閉了我的視覺工作室,一分鍾后重新打開,錯誤消失了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM