skip to Main Content

i have the next question:

I’ve got an .aspx which contains a lot of web controls, this is the one i care:

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

On the selected index changed event of a combo box, i need to call a function of the web control, this is the code of the .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 ;

  }
}

2

Answers


  1. Chosen as BEST ANSWER

    so.. very curious thing.

    when you have a form which contains a lot of user controls, you need to wait for the metadata file to reload the new methods you've created.

    So i closed my visual studio and re opeened a minutes later and the bug desapeared.


  2. you have to make this method static

    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;
    
        }
    }
    

    and you can call using this syntax

    Controls_UCAttachments.loadById(this.id);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search