locked
Button color should get changed from green to Red RRS feed

  • Question

  • User97511230 posted

    Hello everyone.
    I am preparing a simple application in .net 3.5 (Visual Studio 2008, C#).
    We have a business of Real estate. So total of 80 plots. So I have added 80 buttons in the design page, and gave green color to all buttons (indicating that green color plots are available for sale).

    So now, when I click on any of the green colored plot to sell it, it redirects me to new page, where I need to enter the plot details, customer details, mode of payment etc. But I am stuck here. When I enter all the details of the customer, plot details, mode of payment etc and select Plot is "SOLD", the button color should automatically get changed from green to RED. Red color will indicate that the particular plot has been sold. So how can I do this?
    Please help me. Will be very grateful.
    Thanks in advance.

    Wednesday, April 11, 2012 1:14 AM

Answers

  • User1046077057 posted

    Hi,

    Maybe you have used Response.Redirect() in your page. If so, the current page will redirect to another page and you won’t see the button color changed. You can try to open another page in javascript and change the button color in code behind. You can refer to the below code.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript" language="javascript">
            function OpenWindow() {
                window.open("http://localhost:61653/Plot.aspx", null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" BackColor="Green"  />
        </div>
        </form>
    </body>
    </html>
    The below code is in the code behind page.
            protected void Button1_Click(object sender, EventArgs e)
            {
                Button1.BackColor = System.Drawing.Color.Red;
            }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 17, 2012 3:29 AM

All replies

  • User1630798415 posted

    you can use backcolor property to change button color. here is the code

    Button1.BackColor = System.Drawing.Color.Red;

    but, before changing color of button you must have check whether plot is sold or not.

    Wednesday, April 11, 2012 2:47 AM
  • User-1984520607 posted

    Use clickable div instead of button .... you can change the color by applying style sheet.

    it wil be more useful than a button.

    Wednesday, April 11, 2012 3:06 AM
  • User97511230 posted

    No dear. When I enter all the customer details, plot details, mode of payment etc and then when I select "Plot is SOLD", the button color should change from Green to Red automatically. 

    So is there is any way such that, when I select "SOLD", the button color automatically should change to RED color.

    Wednesday, April 11, 2012 5:16 AM
  • User97511230 posted

    Hello dear. I dont have idea about clickable div.. Cry

    Wednesday, April 11, 2012 5:24 AM
  • User1046077057 posted

    Hi,

    Maybe you have used Response.Redirect() in your page. If so, the current page will redirect to another page and you won’t see the button color changed. You can try to open another page in javascript and change the button color in code behind. You can refer to the below code.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript" language="javascript">
            function OpenWindow() {
                window.open("http://localhost:61653/Plot.aspx", null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" BackColor="Green"  />
        </div>
        </form>
    </body>
    </html>
    The below code is in the code behind page.
            protected void Button1_Click(object sender, EventArgs e)
            {
                Button1.BackColor = System.Drawing.Color.Red;
            }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 17, 2012 3:29 AM
  • User839249405 posted
    Hi,
    I hope this will help you .
    <style type="text/css">
    
    .initial2{font-weight:bold;background-color:lime}
    
    </style>
    
    <script type="text/javascript">
    <!--
    
    /***********************************************
    * Rollover background-color button Script- © Dynamic Drive (www.dynamicdrive.com)
    * This notice must stay intact for use
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    //Specify optional button target: "_new" for new window, or name of FRAME target (ie "myframe")
    var buttontarget=""
    
    function change(e, color){
    var el=window.event? event.srcElement: e.target
    if (el.tagName=="INPUT"&&el.type=="button")
    el.style.backgroundColor=color
    }
    
    function jumpto2(url){
    if (buttontarget=="")
    window.location=url
    else if (buttontarget=="_new")
    window.open(url)
    else
    parent[buttontarget].location=url
    }
    
    //-->
    </script>

     

    <form onMouseover="change(event, 'yellow')" onMouseout="change(event, 'lime')">

     <input type="button" value="Yahoo" class="initial2" onClick="jumpto2('http://yahoo.com')">

    <input type="button" value="Google" class="initial2" onClick="jumpto2('http://google.com')">

     <input type="button" value="AlltheWeb" class="initial2" onClick="jumpto2('http://alltheweb.com')"> </form>

    Tuesday, April 17, 2012 6:57 AM