How to write the data from database into an XML file
VB.NET ’Fill the DataSet ds.WriteXml(Server.MapPath (‘products.xml’ ) ) C# //Fill the DataSet ds.WriteXml(Server.MapPath (‘products.xml’ ) ); Note : Make sure you have write and modify rights.
How can I have a particular Web page in an ASP.NET application which displays its own error page.
This can be done by setting the ErroPage attribute of Page Directive or ErrorPage property of Page Class to the desired Custom Error Page <%@Page Language=’C#’ ErrorPage=’specificerropage.htm’%> In web.config <customErrors mode=’On’ />
Can I use custom .NET data types in a Web form?
Yes. Place the DLL containing the type in the application root’s bin directory and ASP.NET will automatically load the DLL when the type is referenced. This is also what happens when you add a custom control from the toolbox to your web form.
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’); } }