Category: ASP.NET
ASP.NET tutorials and snippets
-
Checking File Upload Size using Custom Validator in ASP.NET and Javascript
The following snippet uses custom validator control and javascript to check the file upload size and disabling the form submission if the file size exceeds the limit. The form will not submit if the validator fails. ASPX.PAGE [sc:tcbox ] <asp:FileUpload ID=”fileUpload” runat=”server” /> <br />…
-
Increment Filename Number if exists using c# and asp.net
When you upload a file in asp.net web application and if the file exists it just simply overwrites the existing file. In this example, what we are trying to do is check the filename if it exists. If exists then add an increment number at…
-
Insert Item at top of the DropDownList in ASP.net Codebehind
Here is the snippet, for demo i am pulling the List of States and its ID from the database [sc:tcbox ] ddl_State.DataSource = GetAllStates(); ddl_State.DataTextField = “Title”; ddl_State.DataValueField = “StateID”; ddl_State.DataBind(); ddl_State.Items.Insert(0, new ListItem(“Select State”, “”)); // I am inserting Empty Value at the…
-
Force URL to lower case in ASP.NET using web.config
If your hosting company has IIS rewrite module installed, then you can force all the url in the browser to be in lower case. This is good for SEO as google will see only one url eg. LOWERCASE.ASPX and lowercase.aspx will both point lowercase.aspx page…
-
Force a file to download in asp.net c#
In web applications you may need to download image, zip files, doc files, pdf files, text files. Luckily, Pdf files zip files, doc, docx files will download but images will be displayed by browsers. To force any file to download, we can use the following…
-
-
ASP.NET Membership – Get UserName from UserID or Userkey
To Get the UserName from the ASP.NET membership tables using the UserID or Userkey the following snippet will work. First add the Label Control in the .aspx page Now the snippet in the code behind, in the snippet if you have the UserID first we…
-
ASP.NET Membership – Get UserID from Username
To Get the UserID or UserKey of the logged in User from the ASP.NET membership tables the following snippet will work. First add the Label Control in the .aspx page Now the snippet in the code behind. In the snippet User.Identity.Name gets the current loggedin…
-
ASP.Net countries dropdownlist
For every project we need dropdownlist of countries. Here is the snippet i want to share and use it myself often, so it is handy. The dropdown list comes with country name as text and its 2 letter code as its value.
-
Getting First N words from strings or a title in C#
We can use regular expression to get the first N words from a title or strings. The following example shows how it can be done. This example utilizes RegularExpression namespace eg Result I want only