Home » Posts tagged "ASP.NET" (Page 6)

Archive for the 'ASP.NET' Tag

SqlConnection from web config file in code behind

test.aspx.vb Imports System.Data.SqlClient ————————————- Dim connString As String connString = ConfigurationManager.ConnectionStrings(“MyConnectionString1″).ToString Dim conn As New SqlConnection(connString) web.config <connectionstrings> <add name=”MyConnectionString1″ connectionString=”Data Source=MY-SQL-SRV;Initial Catalog=Northwind; Persist Security Info=True; User ID=my_user;Password=my_pwd” providerName=”System.Data.SqlClient” /> </connectionstrings>

Close thickbox (popup) refresh parent page

Test.aspx <html xmlns=”http://www.w3.org/1999/xhtml”> <head runat=”server”> </head> <body> <form id=”form1″ runat=”server”> < %= Me.UpdMsg %> </form> </body> </html> Test.aspx.vb Protected UpdMsg As String Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)Handles Me.Load If Page.IsPostBack Then UpdMsg = “<a href=’#’ onClick=’parent.location.reload(1)’>Close!</a>” End If End Sub

Form control state in code behind

On page load event we define button css properties Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ‘define control css ValidatUser.Attributes.Add(“class”, “btnSubmit”) vUsername.Attributes.Add(“class”, “txtBox”) ‘on post back page we change the state of control If Page.IsPostBack Then ‘hide validate button ValidateUser.Visible = False ‘disable textbox vUsername.Enabled = False End If End […]