Create Set Of 10 Random Numbers Every Time Page Loads?
Jul 7, 2010
I am trying to create a Question Bank application for one of our clients. What is the main challenge I am facing is a typical demand from the client. What they want is : Whenever users open this site a set of random numbers(range say 1 to 20) should be generated and questions with the QuestionID(column in a table in Database) according to the numbers would be displayed in the page. I have done it to some extent but, still not satisfied with it.
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int[] n = new int[10];
int rn;
bool Check = true;
int[] n1 = new int[10];
Random rand = new Random();
n1[0] = rand.Next(1, 21);
for (int i = 1; i < 10; i++)
{
rn = rand.Next(1, 21);
for (int j = 0; j < n1.Length; j++)
{
if (n1[j] == rn)
{
Check = false;
break;
}
else
continue;
}
if (Check == true)
n1[i] = rn;
}
for(int i=0;i<10;i++)
Response.Write(n1[i] + " ");
}
}
Here are some O/Ps : 11 13 14 4 16 0 0 0 0 0 (1st load)
5 9 8 1 0 0 0 0 0 0 (after refreshing the page)
16 10 20 6 8 17 11 7 0 0 (after refreshing again)
I want that, all these digits in each refresh should be unique(which is comming) but all set should 10 digits(this is not happening).
View 6 Replies
Similar Messages:
Apr 18, 2010
I know there is a class called Random but how do I generate random numbers manually? without using Random class.
View 6 Replies
Jun 14, 2010
I am trying to generate a random number from within a class and am getting "Type 'Random' is not defined" - does anyone have any ideas. Here is the code
**note the code works on an aspx.vb page, but not from within my class
Dim RandomClass As New Random()
Dim RandomNumber As Integer
RandomNumber = RandomClass.Next(3)
View 3 Replies
Jul 4, 2010
From what i know Random() is initialize to the current time. If two connections hit during the same second i should get the same two random numbers? With a large site that can be likely. Locking is bad so how should i solve it? note: the number is used for the session id.
-edit- i am stuck using a long. It feels wrong to shorten a 128bit GUID
View 2 Replies
Feb 1, 2010
I think the title says it all, I have an activeX control, that ask the user if he want's to install it every single time the page loads (Even if it is already installed). Can anyone point me in the right direction? What I have tried so far:
Setting new Guids for the class & interface.
Changing interfaces names & method names.
Changing version number
Uninstalling and re-installing the activeX
View 2 Replies
Sep 27, 2010
I want to generate a unique random number everytime a user submits a form. As the form is submited the data of the form should be placed in a database and a unique random number should be generated so that the user can later use this unique random number to reterieve his details from the database that refer to his unique random id. The unique random number should be atleast 9 digits long.
View 5 Replies
Mar 30, 2011
I have an ID field where I need to insert unique ID's
the ID should be like -
S- (YY)(MM)9999. where, (YY) is year, (MM) is month and 9999(is a four digit random number)
for example - S-11030001
View 5 Replies
Oct 14, 2010
I do long and slow query to get data to my GridView and I got lot of data, but when I'm changing page it loads as slow as at the start, it loads full data again and again, how to load data once and use paging without data loading?
View 1 Replies
Oct 29, 2010
i'm using Random function to generate random numbers and store them into arrayTell me how to do This is how an array is declared
[Code]...
View 10 Replies
Mar 7, 2011
I have 2-3 update panel in my page and i don't want to load chart every time when my page loads or button clicks etc. I put that in update panel with triggers means only some clicks should loads chart. but that chart gets loaded everytime. how to stop that from loading
View 2 Replies
May 9, 2012
So I have a repeater which binds page numbers. That's all fine. I need to know how to make the paging so that they are in "chunks" of a max of 10 page numbers being displayed at a time.Then if they select a page number, it will show the previous x pages and the next y pages (within the 10 chunk range). similar to google paging I guess. Not using pagedDataSource/gridview/gridlist! This is just purely getting the page numbers.
View 1 Replies
Jun 3, 2010
I am streaming HTML content into a Literal control in an ASPX page, and am continually running into a problem where the page loads fine the first time I try it, then subsequent attempts fail to load.
The purpose of the aspx page is to act as a 'broker' to another process that produces streamed HTML output, which then needs to be resolved by the browser.
The reason I'm not just using HtmlTextWriter to stream out the code to the Response object is that the streamed HTML contains framesets, and I am forbidden from modifying that code in any way, so I must keep the streamed code intact. In spite of the fact that frameset HTML hardcoded into the ASPX file would work, it does NOT resolve streamed frameset code!
In any case, streaming into the literal (by creating a string that is assigned to the Literal's Text property) works just fine -- the FIRST time I load that page. If I exit the page, then try to reinstantiate, it FAILS, producing an empty HTML file (containing only "<HTML></HTML>").
View 3 Replies
Mar 15, 2011
So I have a RadPanelBar, and within that a RadTreeView. On a node click event I want so update some control.. for now I am just trying to update a textbox. It works fine except that the first time I click on a child node it takes a very long time to update the control.. Just a simple text change. I set a break point in my function and I noticed that it is taking long to fire the OnNodeClick event.. If I click a parent node in the tree view it loads fine on the first click. Also, after the first time I've clicked it.. it loads quickly.. If I refresh the page, it is slow on the first click again.. Is there something I am missing.. Is the structure of my HTML inappropriate for these AJAX calls? I feel like this is a really simple example that should work..
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="IncidentReportPanel">
[Code]....
EDIT: I updated my code according to this article, [URL] , and the problem persisted... again it only happens the first time..
EDIT: Just to clarify, by updating according to that article, I mean that I removed all the tables and relative widths and replaced them with css positioning and fixed widths.. the problem only happens the first time.. and it only happens sometimes.. quite a few times i thought i solved the problem as it would start responding quickly.. but then after I change my .aspx and change it back (even to the exact same thing when it was working quickly).. I get the same problem..
EDIT: So, I removed the AJAX component.. and setup the control so that it does a PostBack.. and it still takes long to hit my break point.. so it seems that its not an AJAX issue... but for some reason my events are taking long to fire..
EDIT: So I followed the advice on this post and I used the webservices to do my binding and handle everything from the client side code.. All seemed to be ok until I decided that I wanted to return nodes from my webservice that could also be expanded.. So in my webservice I set the ExpandMode of my RadTreeNodeData object to Webservice.. and it renders the data correctly when I expand the child nodes.. However now I see the same problem from before where some calls take 20-30 seconds.. It takes 20-30 seconds to even hit the break point in my webservice.. Should I use the OnClientNodeExpand event instead?
View 3 Replies
Jun 11, 2010
Is there a slick way to convert simple numbers (Army time included) to a time format (am, pm format)? I can do the tedious approach, but I was just wondering if there was another way
0800 => 8:00 am
2317 => 11:17 pm
View 3 Replies
Sep 27, 2010
I want to return random records in term of time whithout NEWID
View 5 Replies
Dec 20, 2010
I have 2 time columns and a difference column. All of these has a varchar datatype. I converted the time in h.mm format. Now I need to round it off to the nearest quarter/half hour(h:15 = h.25, h.30 = h.50, h.45 = h.75) after calculating the difference between the two time values.
Example:
5.08 = 5
5.18 = 5.25
5.34 = 5.50
5.56 = 5.75
View 1 Replies
Sep 3, 2010
i have a query that select random records in access database in terms of time : "SELECT TOP 10 * FROM Tbl ORDER BY Rnd(-10000000*TimeValue(Now())*[ID])" now i wish to convert this query for using in sql server 2005 such that return random records in term of time
View 5 Replies
Mar 11, 2011
I want to create a random password generator in my ASP.NET C# web application.
I have created that but it is applicable only for the integer format. If I give any characters it shows the debugging error as "my input format is wrong".
But i want to enter both string and integer. For example my textbox field may be
[code]....
View 4 Replies
Aug 31, 2010
I am looking for some solution of the random user image.I created some image and calling it from database if user has no image.But i dont like it, it is quite ugly.Is it exists some random image generator, like here in stackoverflow the the user has no photo.
View 2 Replies
Oct 28, 2010
I want to create separate textbox for numbers and string using c# code. I should not use jquery or javascript.
Condition:
Numeric Textbox: It should not allow characters, special characters.
String Textbox: Should not allow numbers, Special characters.
View 3 Replies
Mar 10, 2010
The problem with my web application is when ever i load the home page - The master page as well as content page loads ---This seems fine but when i navigate thorugh the website which have the same Master page but diffrent content page .... the master page loads again. What i want to do is ..I want to keep the master page intact and only the content page loads. How can I accomplish it..
View 3 Replies
Feb 11, 2011
i have seen many site where individual web parts load with busy icon when page loads. without using web parts how can develop a page where individual section will load with busy icon when page loads.
View 1 Replies
Aug 9, 2010
I have a web form (aspx page) where I load case data for my database and edit certain fields. I want to create a queue box where I can display new incoming cases (Case nums) that have not been edited yet, so that I do not mis any cases on a given day. I visualize my queue box to be something like an update panel which updates itself every few minutes and brings the new case nums in the queue box.
View 3 Replies
Jun 12, 2010
How to create sql server table with unique random identity between 45365 - 5782155129452 ?
View 5 Replies
Jun 3, 2010
I have a master page 'Master1' and i have used a content place holder 'content1' and loads pages 'Page1' and 'page2' in the 'content1'. Is there any way to identify which page is loaded to the content place holder whether it is 'Page1' or 'Page2' dynamically.
View 2 Replies