How can I specify the relative path for a file
Suppose you have following file hierarchy: default.aspx Admin/login.aspx Misc/testpage.aspx And you are on the login.aspx and want your user to navigate to the default.aspx (or testpage.aspx) file. Then you can use Response.Redirect (‘../default.aspx’) Response.Redirect (‘../Misc/testpage.aspx’)
How to create a login screen in ASP.NET
Here is a sample login screen: <TABLE id='Table1' cellSpacing='1' cellPadding='1' width='300' border='1'> <TR> <TD> <asp:Label id='Label1' runat='server'>User Name</asp:Label></TD> <TD> <asp:TextBox id='txtUserName' runat='server'></asp:TextBox></TD> <TD> <asp:RequiredFieldValidator id='RequiredFieldValidator1' runat='server' ErrorMessage='*' ControlToValidate='txtUserName'></asp:RequiredFieldValidator></TD> </TR> <TR> <TD> <asp:Label id='Label2' runat='server'>Password</asp:Label></TD> <TD> <asp:TextBox id='txtPassword' runat='server'></asp:TextBox></TD> <TD> <asp:RequiredFieldValidator id='RequiredFieldValidator2' runat='server' ErrorMessage='*' ControlToValidate='txtPassword'></asp:RequiredFieldValidator></TD> </TR> <TR> <TD></TD> <TD> <asp:Button id='btnLogin' runat='server' Text='Login'></asp:Button></TD> <TD></TD> </TR> </TABLE> VB.NET Dim myconnection As SqlConnection Dim mycmd As SqlCommand Dim strSql As String Dim myReader As SqlDataReader Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click myconnection = New SqlConnection('Server=localhost;uid=sa;password=;database=northwind;') strSql = 'Select * from usertbl where username=' & '’' & txtUserName.Text & '’' & ' and userpassword=' & '’' & txtPassword.Text & '’' mycmd = New SqlCommand(strSql, myconnection) myconnection.Open() myReader = mycmd.ExecuteReader(CommandBehavior.CloseConnection) If myReader.Read() Then Response.Write('Welcome') Else Response.Write('Access Denied') End If End Sub C# SqlConnection myconnection ; SqlCommand mycmd ; string strSql ; SqlDataReader myReader ; private void btnLogin_Click(object sender, System.EventArgs e) { myconnection = new SqlConnection('Server=localhost;uid=sa;password=;database=northwind;'); strSql = 'Select * from usertbl where username=' + '’' + txtUserName.Text + '’' + ' and userpassword=' + '’' + txtPassword.Text + '’'; mycmd = new SqlCommand(strSql, myconnection); myconnection.Open(); myReader = mycmd.ExecuteReader(CommandBehavior.CloseConnection); if (myReader.Read() ) { Response.Write('Welcome'); } else { Response.Write('Access Denied'); } }
What is the difference between Server.Transfer and Server.Execute
Server.Transfer is used to End the current weform and begin executing a new webform. This method works only when navigating to a Web Forms page (.aspx) Server.Execute is used to begin executing a new webform while still displaying the current web form. The contents of both forms are combined. This method works only when navigating to a webform page(.aspx)
Can I use a DataReader to update/insert/delete a record
No. DataReader provides a means of reading a forward-only stream of rows from a database.
How to automatically get the latest version of all the asp.net solution items from Source Safe when opening the solution?
In VS.NET you can go to Tools > Options > Source Control > General and check the checkbox for Get everything when a solution opens. This retrieves the latest version of all solution items when you open the solution.