Forum Discussion

Raymond_Morris_'s avatar
Raymond_Morris_
Icon for Nimbostratus rankNimbostratus
Jul 25, 2006

Need a constructor for C# web page?

I've been working with the code from the video example of the simple iControl app (Nice job, Joe. You are a rock star.) I'm trying to use C to write a .NET web page to show a read-only view. Since this is really my first attempt at writing code this way, I was hoping for some help.

 

 

I've used both VS .NET 2003 and VS 2005 with the same issue.

 

I was able to use the principals discussed in the video to overcome certificate erros, etc. However, when I compile I get an error when looping through and updating the list box (here is the code):

 

 

Node.ITCMCommonIPPortDefinition [] node_defs = node.get_node_server_list();

 

 

int [] state = node.get_state_ex(node_defs);

 

 

for(int i=0; i

 

{

 

lb_nodes.Items.Add(

 

Convert.ToBoolean(state[ i ]),

 

node_defs[ i ].address + ":" +node_defs[ i ].port.ToString());

 

}

 

 

This produces an error: "No overload for method 'Add' takes '2' arguments". My research suggests that I need to identify a constructor. Unfortunately, I'm not sure how that is done. Is there a reference that you can point me to?

 

 

I realize that for a read-only page, I don't need a CheckBoxList, but I was trying to stay close to the provided code and set myself up for bigger and better things in the future.

 

 

Thanks in advance,

 

Ray
  • In the video, I used a CheckedListBox which has the following Add() method:

     

     

    Add(object item);
    Add(object item, CheckState check);
    Add(object item, bool isChecked);

     

     

    The ListBox class only has one Add method

     

     

    Add(object item)

     

     

    Odds are that you are using a standard listbox.

     

     

    Also, you have the parameters reversed in your code. The checked state is the second parameter, not the first.

     

     

    private System.Windows.Forms.CheckedListBox lb_nodes;
    .
    .
    .
    //------------------------------------------------------------------------
    // Loop over the items
    //------------------------------------------------------------------------
    for(int i=0; i{
      lb_nodes.Items.Add(
        node_defs[ i ].address + ":" +node_defs[ i ].port.ToString(),
        Convert.ToBoolean(state[ i ]));
    }

     

     

    Try switching your control to a CheckedListBox, switch the parameters and you should be set.

     

     

    -Joe
  • Thanks Joe,

     

     

    I was able to get around this by by making the changes you suggested, and also changing the loop to identify a new listitem this way:

     

     

    for(int i=0; i{

     

    lb_nodes.Items.Add(new ListItem(

     

    node_defs[ i ].address + ":" +node_defs[ i ].port,

     

    Convert.ToString(state[ i ])));

     

    }

     

     

    Now, I am getting erros when compiling that complain of " Cannot convert type 'BigIP1.Node.ITCMCommonIPPortDefinition[]' to 'string' " in this code block (borrowed from another thread in this forum...):

     

     

    UInt64 build64(BigIP1.Node.ITCMLocalLBNode value)

     

    {

     

    return ((string)value.get_node_server_list()<<32)|(string)value.low;

     

    }

     

     

    Without using the above block, I get the same error in this line:

     

     

    Node.ITCMCommonIPPortDefinition [] node_defs = node.get_node_server_list();

     

     

    I've tried other methods, but get the same type conversion errors.

     

     

    Thanks,

     

     

    Ray
  • Things are a bit off. In your first code segment

     

     

    UInt64 build64(BigIP1.Node.ITCMLocalLBNode value)
    {
      return ((string)value.get_node_server_list()<<32)|(string)value.low;
    }

     

     

    you are passing in an interface object (value) and are using it 1) to call the get_node_server_list(); and 2) to access a low value.

     

     

    1) assuming value is an interface to our Node methods, then the get_node_server_list() method returns an array of IPPortDefinitions. IPPortDefinition is a structure that contains an address (string) and a port (long). You are then bit shifting the array of structures and or'ing it to 2).

     

     

    2) If this is an interface to the Node methods, then I'm not sure why you are trying to extract a structure member of low from it.

     

     

    If you are pulling this from the forums, I'm assuming you should be using this format

     

     

    UInt64 build64(Pool.CommonULong64 value)
    {
      return ((ulong)value.high<<32)|(uint)value.low;
    }

     

     

    Where the input parameter is a CommonULong64 value which is a structure with the high and low values of the 64 bit number.

     

     

    As for your second line:

     

     

    Node.ITCMCommonIPPortDefinition [] node_defs = node.get_node_server_list();

     

     

    I'm not sure why this would cause the same error as above ("Cannot convert type "..." to 'string') as you aren't converting it to a string. This looks correct to me as the correct return type from the get_node_server_list() is an array of ITCMCommonIPPortDefinition structures.

     

     

    -Joe