Solved

C# Button Value

Posted on 2009-07-14
4
246 Views
Last Modified: 2012-06-21
I can't grab Button Value in C#. Server message .Web.UI.WebControls.Button' does not contain a definition for 'value'.
In VB I don't get this message.
void Click(object Sender, EventArgs e)

    {

        Button btRes;

        btRes = (Button)Sender;

       switch (btRes.value)

        {

            case "Left":

                contact.Align = "left";

                break;

            case "Right":

                contact.Align = "right";

                break;

            case "Center":

                contact.Align = "center";

                break;

        }

.

.

.

<form runat="server">

    <input type="Button" id="Left" runat="server" value="Left" onserverclick="Click" style="width: 71px; height: 27px" />

    <input type="Button" id="Right" runat="server" value="Right" onserverclick="Click" />

    <input type="Button" id="Center" runat="server" value="Center" onserverclick="Click" />

</form>

Open in new window

0
Comment
Question by:htinawi
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 100 total points
ID: 24856411
Hi htinawi,
You need to call "HtmlInputButton" instead of default web button inside the function.
eg:
These lines:
============
        Button btRes;
        btRes = (Button)Sender;
       
Change to
==========
        System.Web.UI.HtmlControls.HtmlInputButton btRes;
        btRes = (System.Web.UI.HtmlControls.HtmlInputButton)Sender;
0
 

Author Comment

by:htinawi
ID: 24856865
I tried the above. I get effectively the same message.


Compiler Error Message: CS0117: 'System.Web.UI.HtmlControls.HtmlInputButton' does not contain a definition for 'value'

Source Error:

Line 8:          System.Web.UI.HtmlControls.HtmlInputButton btRes;
Line 9:          btRes = (System.Web.UI.HtmlControls.HtmlInputButton)Sender;
Line 10:        switch (btRes.value)
Line 11:         {
Line 12:             case "Left":
 
0
 
LVL 18

Assisted Solution

by:philipjonathan
philipjonathan earned 25 total points
ID: 24857155
It should be 'Value' with capital V. Please give credit to x_com, I'm just helping
0
 

Author Closing Comment

by:htinawi
ID: 31603584
I'm just learning C#.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now