Home » Posts tagged "Visual Studio"

Archive for the 'Visual Studio' 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 = […]

Define control properties in code behind located inside gridview or formview

Markup page <asp:FormView ID=”DefaultPhoto” runat=”server” DataKeyNames=”ge_id” DataSourceID=”ListPhotosDS”> <EditItemTemplate> <img src=”/images/< %# Container.DataItem("photo") %>” class=”detailsmallphoto”/> <asp:Label ID=”photo_idLabel” runat=”server” Text=’< %# Eval("photo_id") %>‘ Visible=”false” /> <asp:LinkButton ID=”UpdateButton” runat=”server” OnClientClick=”return confirm(‘Are you sure you want to remove this photo?’);” CommandName=”Update” /> </EditItemTemplate> </asp:FormView> Code behind DirectCast(DefaultPhoto.FindControl(“UpdateButton”), LinkButton).Text = “Remove” If Page.isPostBack Then DirectCast(DefaultPhoto.FindControl(“UpdateButton”), LinkButton).Text = “Add Photo” End […]

OleDbConnection string with ConfigurationManager

Web config <add name=”MyConnectionString” connectionString=”Data Source=SRV-MY-SQL\SQLCLSTR12; Initial Catalog=MyDatabaseName; Persist Security Info=True;User ID=MyUser;Password=MyPassword” providerName=”System.Data.SqlClient” /> Code behind or markup page ‘defines sql connection Dim connString As String connString = ConfigurationManager.ConnectionStrings(“MyConnectionString”).ToString Dim ConnDB As New OleDbConnection(“Provider=sqloledb;” & connString) ‘define oledbcommand Dim cmd As New OleDbCommand(“SELECT * _ “FROM my_table _ “WHERE name=’Mike’ ;”, ConnDB) Dim reader As […]