Solved

C# Button Value

Posted on 2009-07-14
4
248 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

861 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