Solved

C# Button Value

Posted on 2009-07-14
4
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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 …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

736 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