6 Replies - 319 Views - Last Post: 23 April 2014 - 12:44 PM Rate Topic: -----

#1 WarMacheen  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 08-February 11

C# .Tag

Posted 23 April 2014 - 11:36 AM

I have this code which works in VB and am trying to get it to work in C#

 
            If ListBox1.Items.Count < 10 Then
                ListBox1.Items.Add(NumOne.Text & ListBox1.Tag.ToString() & NumTwo.Text & ("=") & Result.Text)
            End If




This is the code in C#, but the .Tag connected to ListBox1 is creating an error. Is there a way to get it to work or something similar in C#?

'System.Web.UI.WebControls.ListBox' does not contain a definition for 'Tag' and no extension method 'Tag' accepting a first argument of type 'System.Web.UI.WebControls.ListBox' could be found (are you missing a using directive or an assembly reference?}


if (ListBox1.Items.Count < 10)
                {
                    ListBox1.Items.Add(TextBox1.Text + ListBox1.Tag.ToString() + TextBox2.Text + ("=") + TextBox3.Text);
                }

This post has been edited by WarMacheen: 23 April 2014 - 11:37 AM


Is This A Good Question/Topic? 0
  • +

Replies To: C# .Tag

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9383
  • View blog
  • Posts: 35,228
  • Joined: 12-June 08

Re: C# .Tag

Posted 23 April 2014 - 11:38 AM

What are you thinking the '.tag' function does?

Quote

Gets or sets the object that contains data about the control.

http://msdn.microsof...=vs.110%29.aspx

Additionally if you look at the 'webcontrols' functions, do you see a tag in there? I see one for winform controls, but not webcontrols.

http://msdn.microsof...=vs.110%29.aspx
Was This Post Helpful? 0
  • +
  • -

#3 WarMacheen  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 08-February 11

Re: C# .Tag

Posted 23 April 2014 - 11:44 AM

In VB the ListBox.Tag remembered the button pressed such as "+" and I could add it to the string so that the complete string would be something like 2 + 2 = 4

Getting the numbers to the listbox isn't an issue though the operator is.

Right now the listbox reads 11=2 when I press the save button

This post has been edited by WarMacheen: 23 April 2014 - 11:46 AM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9383
  • View blog
  • Posts: 35,228
  • Joined: 12-June 08

Re: C# .Tag

Posted 23 April 2014 - 11:48 AM

Let's slow up on it for a minute. Was this VB in a winform project? If so why is your C# using web controls?

What you described seems to be a bad-hackie use of the '.tag' function in the forms.controls.
Was This Post Helpful? 0
  • +
  • -

#5 WarMacheen  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 08-February 11

Re: C# .Tag

Posted 23 April 2014 - 11:51 AM

View Postmodi123_1, on 23 April 2014 - 11:48 AM, said:

Let's slow up on it for a minute. Was this VB in a winform project? If so why is your C# using web controls?

What you described seems to be a bad-hackie use of the '.tag' function in the forms.controls.


The VB I originally had was not web related, though the C# I'm using is. It's just a simple web page with a calculator and the operations can be saved to a list box and then printed. The listbox can hold 10 items. I have so far managed to get the listbox to show operations without the actual operator, so:

22=4
22=0
22=1

The operator isn't displaying
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9383
  • View blog
  • Posts: 35,228
  • Joined: 12-June 08

Re: C# .Tag

Posted 23 April 2014 - 11:55 AM

Again, let me be clear - .TAG is not an option in the webcontrol side of things. I thought I was pretty clear in post #2. This means you will need to find a new way to track operators being entered. Perhaps an array of buttons to mash for operators.
Was This Post Helpful? 0
  • +
  • -

#7 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4529
  • View blog
  • Posts: 7,898
  • Joined: 08-June 10

Re: C# .Tag

Posted 23 April 2014 - 12:44 PM

There does seem to be a simple solution for this: use a custom attribute and retrieve it in your code:

http://stackoverflow...ms-tag-property

I'd suggest using something like data-tag as your attribute name. That way, you can retrieve it easily from Javascript, and page validators won't complain about invalid attributes (data-whatever attributes are completely valid).

Another option would be to use a hidden input next to your control, with a similar name, and just retrieve both values. Hidden inputs look like this:

<input type="hidden" value="whatever" />
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1