Which are the different ASP.NET authentication modes

ASP.NET supports the following Authentication Providers Windows : Is used in conjunction with IIS authentication. Authentication is performed by IIS in one of three ways: basic, digest, or Integrated Windows Authentication. When IIS authentication is complete, ASP.NET uses the authenticated identity to authorize access Forms : The user provides credentials and submits the form. Passport : Centralized authentication service provided by Microsoft that offers a single logon and core profile services for member sites. None : No Authentication provided. This is default Authentication mode In the web.config file, you can specify this setting: <authentication mode= ‘ [ Windows | Forms | Passport | None ] ‘> </authentication>

How to group the data in the DataList

<asp:DataList id=’DataList1′ runat=’server’ onItemDataBound=’ItemDB’> <HeaderTemplate > <table width=100%> </HeaderTemplate> <ItemTemplate> <tr><td> <asp:Label Runat=server text=<%#DataBinder.Eval(Container.DataITem, ‘Title’)%> ID=’lblTitle’> </asp:Label> <td><asp:Label Runat=server text=<%#DataBinder.Eval(Container.DataITem, ‘LastName’)%> ID=’lblLastName’> </asp:Label> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:DataList> VB.NET Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then BindTitle() End If End Sub ’Bind Data to DataList Populating the Dataset Sub BindTitle() Dim ds As New DataSet Dim sqlStmt As String = ‘SELECT * FROM Employees order by title’ Dim conString As String = ‘server=localhost;database=Northwind;uid=sa;pwd=;’ Dim myda As SqlDataAdapter = New SqlDataAdapter(sqlStmt, conString) myda.Fill(ds, ‘Table’) DataList1.DataSource = ds DataList1.DataBind() End Sub ’The ItemDataBound Event Protected Sub ItemDB(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then Dim strval As String = CType(e.Item.FindControl(‘lblTitle’), Label).Text Dim title As String = ViewState(‘title’) If title = strval Then CType(e.Item.FindControl(‘lblTitle’), Label).Text = ” e.Item.Visible = False Else title = strval ViewState(‘title’) = title CType(e.Item.FindControl(‘lblTitle’), Label).Text = title e.Item.Visible = True End If End If End Sub C# void Page_Load(object sender, EventArgs e) { if (!(Page.IsPostBack)) { BindTitle(); } } void BindTitle() { DataSet ds = new DataSet(); string sqlStmt = ‘SELECT * FROM Employees order by title’; string conString = ‘server=localhost;database=Northwind;uid=sa;pwd=;’; SqlDataAdapter myda = new SqlDataAdapter(sqlStmt, conString); myda.Fill(ds, ‘Table’); DataList1.DataSource = ds; DataList1.DataBind(); } protected void ItemDB(object sender, System.Web.UI.WebControls.DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem | e.Item.ItemType == ListItemType.Item) { string strval = ((Label)(e.Item.FindControl(‘lblTitle’))).Text; string title = ViewState(‘title’); if (title == strval) { ((Label)(e.Item.FindControl(‘lblTitle’))).Text = ”; e.Item.Visible = false; } else { title = strval; ViewState(‘title’) = title; ((Label)(e.Item.FindControl(‘lblTitle’))).Text = title; e.Item.Visible = true; } } }

How to define HeaderTemplate and ItemTemplate to the Repeater at runtime TBD

VB.NET Dim ds As DataSet Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ds = ’Assign proper value to dataset Dim dc As DataColumn Dim dr As DataRow Dim rpthdr As New TemplateBuilder Dim rptitem As New TemplateBuilder Dim strval As String For Each dc In ds.Tables(0).Columns If strval = ” Then strval = dc.ColumnName & ‘ ‘ Else strval = strval & dc.ColumnName & ‘ ‘ End If Next rpthdr.AppendLiteralString(strval) Repeater1.HeaderTemplate = rpthdr Repeater1.DataSource = ds Repeater1.DataBind() End Sub Function getData(ByVal objContainer As System.Web.UI.WebControls.RepeaterItem) As String Dim i As Integer Dim strval As String = ‘<br>’ For i = 0 To ds.Tables(‘table’).Columns.Count – 1 If strval = ” Then strval = objContainer.DataItem(i).ToString & ‘ ‘ Else strval &= objContainer.DataItem(i).ToString & ‘ ‘ End If Next strval = strval & ‘<br>’ Return strval End Function C# DataSet ds; private void Page_Load(object sender, System.EventArgs e) { ds = something; DataColumn dc; DataRow dr; TemplateBuilder rpthdr = new TemplateBuilder(); TemplateBuilder rptitem = new TemplateBuilder(); string strval; foreach (int dc in ds.Tables(0).Columns) { if (strval == ”) { strval = dc.ColumnName + ‘ ‘; } else { strval = strval + dc.ColumnName + ‘ ‘; } } rpthdr.AppendLiteralString(strval); Repeater1.HeaderTemplate = rpthdr; Repeater1.DataSource = ds; Repeater1.DataBind(); } string getData(System.Web.UI.WebControls.RepeaterItem objContainer) { int i; string strval = ‘<br>’; for (int i = 0; i <= ds.Tables(‘table’).Columns.Count – 1; i++) { if (strval == ”) { strval = objContainer.DataItem(i).ToString + ‘ ‘; } else { strval += objContainer.DataItem(i).ToString + ‘ ‘; } } strval = strval + ‘<br>’; return strval; }

How to change the imageurl of the image control that exists in a usercontrol

In the .ascx: <asp:Image id=’Image1′ runat=’server’></asp:Image> In .aspx VB.NET <uc1:UCImage id=’UCImage1′ source=’b2346.jpg’ runat=’server’></uc1:UCImage> Dim UC As UserControl Dim imgUC As System.Web.UI.WebControls.Image UC = Page.FindControl(‘UCImage1’) imgUC = UC.FindControl(‘Image1’) imgUC.ImageUrl = ‘b2346.jpg’ C# UserControl UC ; System.Web.UI.WebControls.Image imgUC ; UC = (UserControl)Page.FindControl(‘UCImage1’); imgUC =(System.Web.UI.WebControls.Image)UC.FindControl(‘Image1’); imgUC.ImageUrl = ‘b2346.jpg’;

How to add user control dynamically into another usercontrol

Here is an example of adding one UserControl into another: uc1.ascx: <asp:Label runat=’server’ text=’uc1′ ID=’Label1′ /> <asp:Panel runat=’server’ id=’p1′ >Panel UC1</asp:Panel> uc2.ascx: <br><asp:Label runat=’server’ text=’uc2′ ID=’Label1′ /> VB.NET Dim uc1 As UserControl = CType(LoadControl(‘uc1.ascx’), UserControl) Controls.Add(uc1) Dim uc2 As Control = uc1.LoadControl(‘uc2.ascx’) Dim p1 As Control = uc1.FindControl(‘p1’) p1.Controls.Add(uc2) C# UserControl uc1 = (UserControl)LoadControl(‘uc1.ascx’); Controls.Add(uc1); Control uc2 = uc1.LoadControl(‘uc2.ascx’); Control p1 = uc1.FindControl(‘p1’); p1.Controls.Add(uc2);