In C#, creating random number is simple and provides multiple options. Random class is used for the same, it’s Next method used to create random number. It also takes min and max value as parameter to create a random number in a range.
Math.random is used to create a random number. But it returns a decimal numal number between between 0 (including) to 1(excluding). Let’s see that
It will create different number each time. So if you want to create a random number say upto 10000 then you can get it by simply writing
var randomnumber = Math.random() * 10000;
Pretty simple Right!!
But it will always create a number less than 10000 (till 9999.999..) and if you take the integer part then the max value you will get 9999. But what if want inclusive of 10000?
Then you can leverage the other method Math.ceil which generates the ceiling number as
For all you will get 7. So if you write the original method as
You will get the number between 0 to 10000 both inclusive. You can also use Math.floor or Math.abs to have your own logic for getting random number in a range.
This is small post but I found it bit interesting and useful sometime.
These are in total three as below
Let’s discuss one by one
It is the simplest one and most widely used to show some message to user in one way. Once the message on browser, it shows OK button which is required to be pressed before moving further as
Syntax is pretty simple
alert("Your meesage to user");
This is another important message box which instead of just showing a message to user, it also accepts the user’s response. It is used to take a Boolean response (true/false) from the user. When displays it show two buttons Ok and Cancel. Ok return true and Cancel returns false. Lets see it
if(confirm("Do you want to proceed"))
// Proceed further
This is another popup message box which is used least. But this can be very helpful in certain scenarios. This allows to take some input from the user. When it is shown to user, it provides an input box in popup where user can enter some text with OK and Cancel button. If OK is pressed then the entered value is passed to the backend else it returns null. It also allows us provide a default value in text box.
var enteredSocialMedia = prompt("Which social media site you use most", "Twitter")
if (enteredSocialMedia == null)
alert("No worries!! You can save your preference any time");
alert("We have saved your preference");
I have used Internet Explorer for this example and if you have used alert or any of them with earlier version of IE like IE 6/7, its looks much better now. It looks different on different browser because its the browser which shows its own popup. Although in most of the cases, we don’t use these popup due to its limitation and look n feel but can help in many scenarios and suitable for small applications.
What is AngulalJS?
I have seen many questions in the forums that how can we bind the CheckBox list from the database via Ajax. There could be many ways to do in an ASP.NET but I will be using the one of the most efficient options available .
In this post, I’ll be using jQuery Ajax to get the data from the server (that will be fetch the data from database) and then will create the CheckBox list dynamically.
Yes it does!!
But let’s first understand that what is a proxy? As we already know whenever we have to use any web service or WCF service, we need to create proxy of that service and with the help of proxy, we use the functionalists provided by the web/WCF service. Proxy acts a intermediary between the client of the service and the actual service. Proxy provides a simple interface to the consumer of service and all the intricacies like creating a connection, creating and sending the request, getting the response etc is handled by the proxy itself.