Solved

C# Button Value

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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…
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!
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

707 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