473,729 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1373
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(Objec t Src, EventArgs E)
{
if(!Page.isPost back)
{
Sfondo.Attribut es.Add("bgcolor ", "#00ff00");
int i=0;
ViewState["num"]=i;
}
}

void Cambia_Sfondo(O bject Src, EventArgs E)
{
int i = (int)ViewState["num"];
if (i==0)
{
Sfondo.Attribut es.Add("bgcolor ", "#0000ff");
i++;
}
else
{
Sfondo.Attribut es.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
1698
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 change the control with index 3 to 2, and 4 to 3. (push up) ... so when I add new control to the panel, the new control will have the index 4.
3
4766
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
1555
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 also appears in the bottom left bar of the application. I'm more interested in the actual technology behind this. How is the 'Push' implemented? Script Callbacks, XMLHTTP, or is it a true 'Push' with Subsriber/Publisher functionality? ...
41
2527
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 my purposes. As this code was posted long time ago (November 1998) I would like to ask if the principles used in this code are still valid in the "modern" Python and if/how it can be improved (revrited) using futures of current version of...
0
2810
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 live audio on specific port. I am using Windows media encoder sdk sample (entire code), currently i
4
1472
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 to a user. For example: If I'm speaking to you on the phone and I'm reviewing the purchase of a product and we are looking at options. I want to show you options X. I'd like to push you a webpage to your IP address. Then if I want to show you...
4
1480
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 ){ @result_line = (); push @result_line, $result_line1; push @result_line, $result_line2;
2
2941
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 method. What I am trying to accomplish is to detect if a value has changed in any cell so that if a user closes the form without saving first, I want to prompt to save changes. I don't want to prompt if there were no changes.
5
2464
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: self.push_with_producer(ProducerA()) return asynchat.async_chat.readable(self)
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.