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=”https://www.mydomain.com”/>    <add key=”NonSSLURL” value=”http://www.mydomain.com”/> 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: http://www.freevbcode.com/ShowCode.asp?ID=1968 ‘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 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 = “someone@someemail.com“    Dim sFrom As String = “me@myemail.com“    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.