Home » Posts tagged "ASP.NET"

Archive for the 'ASP.NET' Tag

Validate date in code behind with regex – VB.NET

Code behind ‘define public var Protected StartDate As String Protected EndDate As String ‘define other var Dim sDate = Request.Form(“startDateTbx”) Dim eDate = Request.Form(“endDateTbx”) Dim r As Regex r = New Regex(“^(0[1-9]|[1-9]|1[012])/(0[1-9]|[1-9]|[12][0-9]|3[01])/20\d\d$”) ‘run validation If sDate = “” Then startDateLbl.Text = “Required” ElseIf Not r.Match(sDate).Success Then startDateLbl.Text = “Invalid date. Use mm/dd/yyyy.” Else startDateLbl.Text = […]

Captcha – VB.NET

Email form <tr> <td></td> <td></td> </tr> <tr> <td></td> <td><img style=”WIDTH: 119px; HEIGHT: 34px” alt=”” src=”Captcha.aspx” />  <a href=””>Can’t Read?</a></td> </tr> <tr> <td></td> <td><asp:textbox runat=”server” ID=”txtcaptcha”></asp:textbox></td> </tr> <tr> <td></td> <asp:ImageButton ID=”ContactSeller” CausesValidation=”True” runat=”server” ImageURL=”/images/buttons/btn_submit.gif” /></td> </tr> Email page code behind …. Dim captchaStr As String = Session(“randomStr”) Dim captchaTxt As TextBox = ContactSeller.FindControl(“txtcaptcha”) If captchaStr captchaTxt.Text.ToString […]

Add item on the dropdownlist – VB.NET

Markup page <!– ‘define control –> <asp:DropDownList ID=”MySelectionDDL” runat=”server” AutoPostBack=”True” AppendDataBoundItems=”true” DataSourceID=”MySelectionDS” DataTextField=”Text” DataValueField=”Value” OnDataBound=”MySelectionDDL_DataBound”> <!– ‘define datasource –> <asp:SqlDataSource ID=”MySelectionDS” runat=”server” ConnectionString=”< %$ ConnectionStrings:my_sql_connection %>” SelectCommand=”SELECT [Text], [Value] FROM [MyTable] ORDER BY [Text]”> </asp:SqlDataSource> Code behind Protected Sub MySelectionDDLDataBound(ByVal sender As Object, ByVal e As EventArgs) ‘add item at the beginning of the list […]