473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

To change color with a push-button

I must make a aspx page that make these single steps:
1. when I open it is green
2. when I click a button it is blue
3. when I click the same button it is red

alternate 2 and 3

I have written this code but it does not work. Which thing I am mistaking?

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ Page Language="C#"%>
  3.  
  4. <script runat="server">
  5.  
  6. bool T=false;
  7. int a=1;
  8.  
  9. protected void Page_Load(Object Src, EventArgs E)
  10. {
  11. Sfondo.Attributes.Add("bgcolor", "#00ff00");
  12. }
  13.  
  14. void Cambia_Sfondo(Object Src, EventArgs E)
  15. {
  16. T=!T;
  17. if (T)
  18. {
  19. Sfondo.Attributes.Add("bgcolor", "#0000ff");
  20. }
  21. else
  22. {
  23. Sfondo.Attributes.Add("bgcolor", "#ff0000");
  24. }
  25. a++;
  26. }
  27.  
  28. </script>
  29.  
  30. <html>
  31. <body id="Sfondo" runat="server">
  32. <form runat="server">
  33. <asp:Button OnClick="Cambia_Sfondo" Text="Cambia Sfondo" Height="20"
  34. Width="80" runat="server"/>
  35. <br><%Response.Write("A= " + a);%>
  36. </form>
  37. </body>
  38. </html>
  39.  
  40.  

Nov 19 '05 #1
1 1359
Firstly the boolean logic won't work, secondly you need to store the
value of i in either viewstate or the session each time, try this code

<script runat="server">

protected void Page_Load(Object Src, EventArgs E)
{
if(!Page.isPostback)
{
Sfondo.Attributes.Add("bgcolor", "#00ff00");
int i=0;
ViewState["num"]=i;
}
}

void Cambia_Sfondo(Object Src, EventArgs E)
{
int i = (int)ViewState["num"];
if (i==0)
{
Sfondo.Attributes.Add("bgcolor", "#0000ff");
i++;
}
else
{
Sfondo.Attributes.Add("bgcolor", "#ff0000");
i = 0;
}
ViewState["num] = i;
}

</script>

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tee | last post by:
Hi, Does anyone know how to change an index of an object? This is what I want to do. eg: I have 5 controls in a panel. index from 0 to 4, after I remove the 3rd control (index 2), I want to...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
1
by: paul | last post by:
I'd like to replicate the push technology of Microsoft OutLook Web where when a new email is sent to the logged in user a temporary window pops up with the text 'You have new mail'. The same text...
41
by: Petr Jakes | last post by:
Hello, I am trying to study/understand OOP principles using Python. I have found following code http://tinyurl.com/a4zkn about FSM (finite state machine) on this list, which looks quite useful for...
0
by: Crisco www.misericordia.com.br | last post by:
Hi I m working on WEBRADIO Software. im using Windows media encoder 9 SDK on Windows 2003 server using VB.NET. My current scenario is my soundcard . My application will push my server the...
4
by: Mark Siler | last post by:
First let me say I'm not a developer. I'm looking for someone that can either do this for me or point me to a technology that can. I'm in need of a way via the Internet to push a screen or webpage...
4
by: Studentmadhura05 | last post by:
Hi I am trying to Push one line at a time from three different arrays into a new array Here is a part of the code that is giving trouble: my @result_line; while ($entries >= 0 ){...
2
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Greetings, I am trying to find out how to do something that on the surface seems like it should be very simple to do. I have a datagrid with a datatable bound to it using the SetDataBinding...
5
by: ludvig.ericson | last post by:
Hello, My question concerns asynchat in particular. With the following half- pseudo code in mind: class Example(asynchat.async_chat): def readable(self): if foo:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.