Archive / ASP.Net

RSS feed for this section

C# Fill a Dropdown List and For Loop

Here is a quick syntax for a For loop and filling a dropdown list with an incrementing number using C#. for (Int16 i = 1; i <= iMax; i++) {    ListItem item = new ListItem(i.ToString()); ;    ddlNumber.Items.Add(item); }

Force SSL ON or OFF Function

When working on a site that may have some pages in SSL (the check out pages) and most pages not I use a function to switch between SSL and Non SSL pages. First, I set the non secure and SSL URL’s in the config file under appSettings:     <add key=”SSLURL” value=””/>    <add key=”NonSSLURL” value=””/> Next, in […]

JavaScript Code To Toggle Check Boxes

Here is some JavaScript code to toggle check boxes (same action as radio buttons). In the page load event register the JavaScript:    chkTwoYear.Attributes.Add(“onclick”, “javascript: CheckTwoProgram(” + chkTwoYear.ClientID + “);”);    chkFourYear.Attributes.Add(“onclick”, “javascript: CheckFourProgram(” + chkFourYear.ClientID + “);”); In the HTML of the page add the JavaScript: <SCRIPT Language=”JavaScript”><!– function CheckTwoProgram(id) {    if(id.checked)       document.forms[0].chkFourYear.checked=false;    } function CheckFourProgram(id) {    if(id.checked)       document.forms[0].chkTwoYear.checked=false;    } //–> </SCRIPT>

VB.Net Format Phone Number Function

Here is a function to format phone numbers. I picked it up from here: ‘Takes any entered phone number and returns it in ###-#### format‘or (###) ###-#### Public Function FormatPhoneNumber(ByVal sNumToBeFormatted As _   String) As String Dim iNumberLength As Integer ‘Used for the Phone Number length   ‘Trim any leading and trailing spaces sNumToBeFormatted = […]

How to run client side javascript on a server control

Here is some code to run a javascript function on the client side when a value changes in a drop down box. In this case I have a list of dates populating a drop down box. When the date changes the value of a DIV section changes to a corresponding end date. In the appSetting […]

How to send an email by authenticating with any mail server

If you want to send an email from an application that might not be on a server that allows relaying you can use the System.Net.NetworkCredential. Just add your account login and password and your email will route through the remote server.     Dim sTo As String = ““    Dim sFrom As String = ““    Dim […]

GridView Format Note

When applying a Format expression in the DataFormatString property of a column such as “{0:d}” the HtmlEncode property must be set to False. If HtmlEncode is set to True the format expression will not be applied.