How can we programmatically verify whether the UserName and Password is Correct?
The programmatic verification of username and password can be done by the below code by the Login1_Authenticate method protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { if((Login1.UserName==’User’)&&(Login1.Password==’Password’)) { Label1.Text=’LogIn Successful’; } else { Label1.Text=’LogIn Failed – Try Again’; } }
What is the difference between Response.Redirect() and Server.Transfer().
Response.Redirect Transfers the page control to the other page, in other words it sends the request to the other page. Causes the client to navigate to the page you are redirecting to. In http terms it sends a 302 response to the client, and the client goes where it’s told. Server.Transfer Only transfers the execution to another page and during this you will see the URL of the old page since only execution is transferred to new page and not control. Occurs entirely on the server, no action is needed by the client Sometimes for performance reasons, the server method is more desirable
My ASP code gives an error ‘Compiler Error Message: BC30289: Statement cannot appear within a method body. End of method assumed’ when changed to .aspx
Use a <script runat=server> block instead of the <% %> syntax to define Subs. Make sure you have proper events associated with the code and have start and end of procedure or function written properly.
How to display ‘No data exists’ within the datagrid rather than just showing Column Headers with no rows
<asp:DataGrid id=’DataGrid1′ OnItemDataBound =’ItemDB’ runat=’server’></asp:DataGrid> VB.NET Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ’ Put user code to initialize the page here If Not Page.IsPostBack Then ’Populate the dataSet ’Bind the dataGrid with the dataView DataGrid1.DataSource = BindTheDataClass.Binddata().Tables(0).DefaultView DataGrid1.DataBind() End If End Sub ’Page_Load Protected Sub ItemDB(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Dim dv As DataView = CType(DataGrid1.DataSource, DataView) Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView) If dv.Table.Rows.Count = 0 Then ’By default the Datagrid Header is shown in case there is no Data Available ’So in case of No Data found ’Check the ListItemType.Header If e.Item.ItemType = ListItemType.Header Then Dim i As Integer = e.Item.Cells.Count ’Assign ‘No Search result Found’ in one of the cells of DataGrid e.Item.Cells(0).Text = ‘No Search Results Found’ ’Remove Rest of the empty cells from Datagrid Dim j As Integer For j = i – 1 To 1 Step -1 e.Item.Cells.RemoveAt(j) Next End If End If End Sub ’ItemDB C# private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if (!Page.IsPostBack ) { //Fill DataSet //Bind the DataGrid with the DataView DataGrid1.DataSource =ds.Tables[0].DefaultView ; DataGrid1.DataBind (); } } protected void ItemDB(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { DataView dv =(DataView)DataGrid1.DataSource ; DataRowView drv = (DataRowView)e.Item.DataItem ; if (dv.Table.Rows.Count == 0 ) { //By default the Datagrid Header is shown in case there is no Data Available //So in case of No Data found //Check the ListItemType.Header if ((e.Item.ItemType == ListItemType.Header)) { int i= e.Item.Cells.Count; //Assign ‘No Search result Found’ in one of the cells of DataGrid e.Item.Cells [0].Text = ‘No Search Results Found’; //Remove Rest of the empty cells from Datagrid for (int j=i-1;j>0;j–) { e.Item.Cells.RemoveAt(j); } } } }
Can I receive both HTML markup for page and code in the ASP.NET web page’s source code portion in the Web browser
No. The Web browser receives only HTML markup. No source code or web control syntax is passed back to the web browser.