//dynamically add 20 years from this year to drop-down
var select = document.getElementById(“ccexp”);
var startYear = new Date().getFullYear();
var option, currentYear, currentYearString, currentYearTwoDigit;
for (var i = 0; i <= 20; i++) {
currentYear = startYear + i;
currentYearString = currentYear.toString();
currentYearTwoDigit = currentYearString.substring(2);
option = document.createElement(“option”);
option.setAttribute(“value”, currentYearTwoDigit);
option.appendChild(document.createTextNode(currentYear));
select.appendChild(option);
}
Javascript to append options to a select element
Category: 3DW DevTools
select multiple elements by class, and loop through them with javascript
I have a table with elements in it. I need to target them and change the css class.
<div class="dwtooltip"><img src="note_icon.png" /><span class="dwtooltiptext">my tooltip text here.</span></div>
const items = document.querySelectorAll(‘.dwtooltip’);
if(items){}
for (var i=0; i < items.length; i++) {
console.log(i);
items.forEach(function(el){
el.classList.add(“notooltip”);
el.classList.remove(“dwtooltip”);
});
}
Get the value from between parenthesis c#
Many times you have data in a format that needs to be parsed. One thing I have come across lately is needing to get a value from between parenthesis.
Data: Here is my description and it has a code.(1234)
I need to get the code of 1234 from the data.
string value = "Here is my description and it has a code.(1234)"; int startIndex = value.IndexOf('('); int endIndex = value.IndexOf(')'); int length = endIndex - startIndex; if (startIndex > -1 && endIndex > -1) { return value.Substring(startIndex + 1, length-1); } else return "There are no parenthesis in the value.";
Local email delivery : Dump email from an app into a local directory for testing
While devving an app on localhost, the email scripts error out and you cant test what the message would have looked like. With this handy snippet, you can dump any email from your app into a local directory. Slap this into your dev web config file.
<mailSettings> <smtp deliveryMethod="SpecifiedPickupDirectory"> <specifiedPickupDirectory pickupDirectoryLocation="C:\MailDump\" /> <network host="localhost"/> </smtp> </mailSettings>
Add an ID to the rows of a GridView table
It can be handy to have each row have an ID for use with client side scripting. By default the asp gridview does not come with ids for the rows. Use the row databound event to add them
protected void GridViewFullView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { GridViewRow row = e.Row; row.Attributes["id"] = GridViewFullView.DataKeys[e.Row.RowIndex].Value.ToString(); } }
Check if string contains only letters and/or numbers
Its super easy to validate if a string does not have any special characters in it.
Bool isValid(string inputText) { return inputText.All(Char.IsLetterOrDigit); }
Add “Please select” message to databound dropdown list c#
So you have dropdown lists, populated with data from your data storage solution. You need to prepend the lists with messages such as “Please select an option”.
public void addMessageToDropdown(DropDownList whatDropdown, string ddmessage) { DropDownList list = whatDropdown as DropDownList; if(list != null) { list.Items.Insert(0, ddmessage); } }
Add years to dropdown
Need a dropdown list with some years in it and a custom message as the first choice? How about this to start with: current year through 6 years into the future. Add a dropdownlist control to the page and call this function on pageload.
public void addYearsToDropdown(DropDownList whatDropdown, string ddmessage) { DropDownList list = whatDropdown as DropDownList; if(list != null) { list.Items.Insert(0, ddmessage); } int curYear = System.DateTime.Now.Year - 1; for(int i = 1; i < 6; i++) { list.Items.Insert(i, (curYear + i).ToString()); } }
addMessageToDropdown(DropDownListYears, “–Select A Year–“);
Firewall and Web application security
Cloudflare is a cloud based web application security firewall.
https://www.cloudflare.com/security/
Security
Cloudflare Security Services reduce the risk of lost customers, declining revenues, and degraded brand by protecting against DDoS attacks, abusive bots, and data breach.
-
Anycast Network
With 122 data centers across 58 countries and 15 Tbps of capacity, Cloudflare’s Anycast network absorbs distributed attack traffic by dispersing it geographically, while keeping Internet properties available and performant. -
DNSSEC
DNSSEC is the Internet’s non-spoofable caller ID. It guarantees a web application’s traffic is safely routed to the correct servers so that a site’s visitors are not intercepted by a hidden “man-in-the-middle” attacker. -
Web Application Firewall (WAF)
Cloudflare’s enterprise-grade web application firewall (WAF) detects and block common application layer vulnerabilities at the network edge, utilising the OWASP Top 10, application-specific and custom rulesets. -
Rate Limiting
Rate Limiting protects critical resources by providing fine-grained control to block or qualify visitors with suspicious request rates. -
SSL / TLS
Transport Security Layer (TLS) encryption enables HTTPS connections between visitors and origin server(s), preventing man-in-the-middle attacks, packet sniffing, the display of web browser trust warnings, and more. -
Secure Registrar
Cloudflare is an ICANN accredited registrar, protecting organizations from domain hijacking with high-touch, online and offline verification for any changes to a registrar account. -
Orbit
Cloudflare Orbit solves security-related issues for Internet of Things devices at the network level. -
Warp
Automatically secure, accelerate, route, and load balance applications and services without directly exposing them to the internet. -
Workers
Cloudflare Workers let developers run JavaScript Service Workers in Cloudflare’s 122 data centers around the world. -
Access
Secure, authenticate, and monitor user access to any domain, application, or path on Cloudflare.
Checking boxes in a C# ASP checkbox list using values from a database
Suppose you have an ASP checkbox list and you need to check the boxes using data returned from the information storage.
You have a couple of ways the data could have been stored. If each checkbox option is a separate field in the database, you could go with a simple loop, but if they have been stored in one field, you need to put some programming power into it.
Here’s a scenario. I have a “seasons” checklist. There are values stored in the db that the user selected. For example if they chose Summer and Fall, the db string “seasons” would contain “Summer Fall”.
<asp:CheckBoxList ID="CheckBoxListSeasons" runat="server"> <asp:ListItem>Summer</asp:ListItem> <asp:ListItem>Fall</asp:ListItem> <asp:ListItem>Winter</asp:ListItem> <asp:ListItem>Spring</asp:ListItem> </asp:CheckBoxList>
In order to display the list with the Summer and Fall boxes checked, I would do this:
string seasons = "Summer Fall" for (int i = 0; i < CheckBoxListSeasons.Items.Count; i++) { if (seasons.Contains(CheckBoxListSeasons.Items[i].Value)) { CheckBoxListSeasons.Items[i].Selected = true; } } // end checkbox loop