Solved

C# Button Value

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How do I get the unique ID after insert? 87 92
.NET Error 7 42
XML to SQL Table using c# 5 47
Get String split 5 33
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

12 Experts available now in Live!

Get 1:1 Help Now