Click here to Skip to main content
15,904,348 members
Home / Discussions / C#
   

C#

 
AnswerRe: List of running applications Pin
Judah Gabriel Himango6-Apr-06 10:02
sponsorJudah Gabriel Himango6-Apr-06 10:02 
QuestionRandom in C# Pin
alee15.10.886-Apr-06 8:21
alee15.10.886-Apr-06 8:21 
GeneralRe: Random in C# Pin
Office Lineman6-Apr-06 8:35
Office Lineman6-Apr-06 8:35 
GeneralRe: Random in C# Pin
alee15.10.886-Apr-06 8:40
alee15.10.886-Apr-06 8:40 
AnswerRe: Random in C# Pin
Office Lineman6-Apr-06 8:45
Office Lineman6-Apr-06 8:45 
GeneralRe: Random in C# Pin
alee15.10.886-Apr-06 9:11
alee15.10.886-Apr-06 9:11 
GeneralRe: Random in C# Pin
junglerover776-Apr-06 16:26
junglerover776-Apr-06 16:26 
AnswerRe: Random in C# Pin
Jakob Farian Krarup6-Apr-06 8:46
Jakob Farian Krarup6-Apr-06 8:46 
Hi Alee Big Grin | :-D

It would be helpful if you told us whether this is a windows- or web application. But I guess you're talking about web.

You could store the number of times in ViewState (a hidden form field on the webpage)

Something along the lines of:
http://www.sweetsilence.dk/codeprojectprojects/limitedclicks/[^]

Here is the code below, also available at:
http://www.sweetsilence.dk/codeprojectprojects/limitedclicks/limitedclicks.zip[^]

--------------------------------------------------------------------------
public class WebForm1 : System.Web.UI.Page
{
	protected System.Web.UI.WebControls.Label lblQuote;
	protected System.Web.UI.WebControls.Label lblNumberOfClicksLabel;
	protected System.Web.UI.WebControls.Label lblNumberOfClicksValue;
	protected System.Web.UI.WebControls.Button btnShowQuote;
	
	//makes it easier to store an int in ViewState by wrapping it in a property
	protected int NumberOfClicks
	{
		get 
		{
			//if there is no value in ViewState, return 0 (zero)
			if(this.ViewState["clicks"] == null)
				return 0;
			else
				return (int)ViewState["clicks"];
		}
		set{this.ViewState["clicks"] = value;}
	}

	private void btnShowQuote_Click(object sender, System.EventArgs e)
	{
		//if there are still clicks left
		if(this.NumberOfClicks < 10)
		{
			//show quote
			lblQuote.Text = GetQuote();
			//increment number of clicks
			NumberOfClicks++;
		}
		else
		{
			//let them know that the show is over
			lblQuote.Text = "[no more quotes for you!]";
			lblQuote.ForeColor = Color.Red;
		}
	}

	public string GetQuote()
	{
		//implement your own code to get random quote
		if(this.NumberOfClicks % 2 == 0
			return "Even is pretty good";
		else
			return "Odd is good too ; )";
	}

	private void WebForm1_PreRender(object sender, System.EventArgs e)
	{
		lblNumberOfClicksValue.Text = this.NumberOfClicks.ToString();
	}
} 

Three kinds of people in the world:
- Those who can count..
- Those who can't!

-- modified at 14:47 Thursday 6th April, 2006
GeneralRe: Random in C# Pin
alee15.10.886-Apr-06 9:07
alee15.10.886-Apr-06 9:07 
GeneralRe: Random in C# Pin
Jakob Farian Krarup6-Apr-06 9:37
Jakob Farian Krarup6-Apr-06 9:37 
QuestionToolStripRenderer Pin
vishalkarlay6-Apr-06 6:49
vishalkarlay6-Apr-06 6:49 
AnswerRe: ToolStripRenderer Pin
Judah Gabriel Himango6-Apr-06 6:56
sponsorJudah Gabriel Himango6-Apr-06 6:56 
QuestionHow to declare virtual Columns Pin
mrkeivan6-Apr-06 6:20
mrkeivan6-Apr-06 6:20 
AnswerRe: How to declare virtual Columns Pin
Office Lineman6-Apr-06 8:42
Office Lineman6-Apr-06 8:42 
GeneralRe: How to declare virtual Columns Pin
mrkeivan6-Apr-06 9:11
mrkeivan6-Apr-06 9:11 
AnswerRe: How to declare virtual Columns Pin
Office Lineman6-Apr-06 9:30
Office Lineman6-Apr-06 9:30 
QuestionListBox problem Pin
Ready4u6-Apr-06 6:09
Ready4u6-Apr-06 6:09 
AnswerRe: load + save ADO.NET and c# Pin
Judah Gabriel Himango6-Apr-06 5:40
sponsorJudah Gabriel Himango6-Apr-06 5:40 
Questionsql command + datagridView Problem Pin
mrkeivan6-Apr-06 5:14
mrkeivan6-Apr-06 5:14 
Questiondbf database files import net2.0 Pin
hpetriffer6-Apr-06 4:44
hpetriffer6-Apr-06 4:44 
QuestionDataGrid in .net 1.1 and 2.0 ??? Pin
amin_behzadi6-Apr-06 4:41
professionalamin_behzadi6-Apr-06 4:41 
AnswerRe: DataGrid in .net 1.1 and 2.0 ??? Pin
NeelV7-Apr-06 2:49
NeelV7-Apr-06 2:49 
QuestionMoving files programatically Pin
naglbitur6-Apr-06 4:14
naglbitur6-Apr-06 4:14 
AnswerRe: Moving files programatically Pin
Judah Gabriel Himango6-Apr-06 4:28
sponsorJudah Gabriel Himango6-Apr-06 4:28 
GeneralRe: Moving files programatically Pin
naglbitur6-Apr-06 5:09
naglbitur6-Apr-06 5:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.