Does session state have a locking mechanism that serialize the access to state?
Session state implements a reader/writer locking mechanism: A page (or frame) that has session state write access (e.g. <%@ Page EnableSessionState=’True’ %>) will hold a writer lock on the session until the request finishes. A page (or frame) that has session state read access (e.g. <%@ Page EnableSessionState=’ReadOnly’ %>) will hold a reader lock on the session until the request finishes. Reader lock will block a writer lock; Reader lock will NOT block reader lock; Writer lock will block all reader and writer lock. That’s why if two frames both have session state write access, one frame has to wait for the other to finish first
How to filter xml data and display data in the DataGrid
<?xml version=’1.0′ encoding=’utf-8′ ?> <products> <product prodId=’product1-00′ param1=’11’ /> <product prodId=’product1-00′ param1=’12’ /> <product prodId=’product1-01′ param1=’13’ /> <product prodId=’product1-02′ param1=’14’ /> <product prodId=’product2-00′ param1=’21’ param2=’22’ /> <product prodId=’product2-00′ param1=’31’ param2=’32’ /> <product prodId=’product2-01′ param1=’41’ param2=’42’ /> </products> VB.NET Dim ds As New DataSet ds.ReadXml(Server.MapPath(‘data1.xml’)) Dim dv As New DataView dv = ds.Tables(0).DefaultView dv.RowFilter = ‘prodId=’product2-00’’ Me.DataGrid1.DataSource = dv Me.DataBind() C# DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath(‘data1.xml’)); DataView dv = new DataView(); dv = ds.Tables[0].DefaultView; dv.RowFilter = ‘prodId=’product2-00’’; this.DataGrid1.DataSource = dv; this.DataBind();
How to View one record per page in ASP.NET
<asp:label id=’Label2′ style=’Z-INDEX: 106; LEFT: 111px; POSITION: absolute; TOP: 83px’ runat=’server’>Product ID</asp:label> <asp:label id=’Label1′ style=’Z-INDEX: 105; LEFT: 110px; POSITION: absolute; TOP: 43px’ runat=’server’>Product Name</asp:label> <asp:textbox id=’txtProductName’ style=’Z-INDEX: 104; LEFT: 206px; POSITION: absolute; TOP: 83px’ runat=’server’ OnDataBinding=’txtDataBind’></asp:textbox> <asp:textbox id=’txtProductid’ style=’Z-INDEX: 103; LEFT: 204px; POSITION: absolute; TOP: 43px’ runat=’server’> <asp:button id=’btnPrevious’ style=’Z-INDEX: 102; LEFT: 137px; POSITION: absolute; TOP: 126px’ runat=’server’ Text=’Previous’ OnClick =’PrevBtn’></asp:button> <asp:button id=’btnNext’ style=’Z-INDEX: 101; LEFT: 243px; POSITION: absolute; TOP: 126px’ runat=’server’ Text=’Next’ OnClick =’NextBtn’></asp:button> 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 Try ’Fill the DataSet If Not Page.IsPostBack Then ViewState(‘CurrentPos’) = 0 Me.DataBind() End If Catch ex As Exception Response.Write(ex.Message & ex.StackTrace) End Try End Sub protected Sub NextBtn(ByVal sender As System.Object, ByVal e As System.EventArgs) Try Dim CurrentPos As Integer = CType(ViewState(‘CurrentPos’), Integer) CurrentPos += 1 If CurrentPos > ds.Tables(0).Rows.Count Then CurrentPos -= 1 End If ViewState(‘CurrentPos’) = CurrentPos Me.DataBind() Catch ex As Exception Response.Write(ex.Message) End Try End Sub protected Sub PrevBtn(ByVal sender As System.Object, ByVal e As System.EventArgs) Try Dim CurrentPos As Integer = CType(ViewState(‘CurrentPos’), Integer) If CurrentPos > 0 Then CurrentPos -= 1 End If ViewState(‘CurrentPos’) = CurrentPos Me.DataBind() Catch ex As Exception Response.Write(ex.Message) End Try End Sub protected Sub txtDataBind(ByVal sender As Object, ByVal e As System.EventArgs) Try Dim CurrentPos As Integer = CType(ViewState(‘CurrentPos’), Integer) ViewState(‘CurrentPos’) = (CurrentPos) txtProductid.Text = ds.Tables(0).Rows(CurrentPos).Item(‘productid’) txtProductName.Text = ds.Tables(0).Rows(CurrentPos).Item(‘productname’) Catch ex As Exception Response.Write(ex.Message) End Try End Sub C# DataSet ds; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here //Fill the DataSet if (!Page.IsPostBack ) { ViewState[‘CurrentPos’] = 0 ; this.DataBind() ; } } protected void PrevBtn(object sender, System.EventArgs e) { try { int CurrentPos = (int)ViewState[‘CurrentPos’] ; if (CurrentPos > 0 ) { CurrentPos -= 1 ; } ViewState[‘CurrentPos’] = CurrentPos ; this.DataBind() ; } catch (Exception ex) { Response.Write(ex.Message) ; } } protected void NextBtn(object sender, System.EventArgs e) { try { int CurrentPos = (int)ViewState[‘CurrentPos’] ; CurrentPos += 1 ; if( CurrentPos > ds.Tables[0].Rows.Count) { CurrentPos -= 1 ; } ViewState[‘CurrentPos’] = CurrentPos ; this.DataBind() ; } catch (Exception ex) { Response.Write(ex.Message) ; } } protected void txtDataBind(Object sender , System.EventArgs e ) { try { int CurrentPos = (int) ViewState[‘CurrentPos’]; ViewState[‘CurrentPos’] = CurrentPos ; txtProductid.Text = ds.Tables[0].Rows[CurrentPos][‘productid’].ToString(); txtProductName.Text = ds.Tables[0].Rows[CurrentPos][‘productname’].ToString (); } catch (Exception ex) { Response.Write(ex.Message) ; } }
How to display multiple spaces in a dropdownlist
<asp:DropDownList id=’DropDownList1′ runat=’server’></asp:DropDownList> 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 Dim i As Integer For i = 0 To 10 DropDownList1.Items.Add(‘Item Number’ + SpaceDDL(10) + i.ToString) Next End Sub Private Function SpaceDDL(ByVal numberOfSpaces As Integer) As String Dim Spaces As String Dim i As Integer For i = 0 To numberOfSpaces Spaces &= ‘ ‘ Next Return Server.HtmlDecode(Spaces) End Function C# private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here for(int i = 0 ;i<=10;i++) { DropDownList1.Items.Add(‘Item Number’ + SpaceDDL(10) + i.ToString()); } } string SpaceDDL(int numberOfSpaces ) { string Spaces=”; for(int i = 0 ;i<=numberOfSpaces;i++) { Spaces += ‘ ‘; } return Server.HtmlDecode(Spaces); }
How to right align the text in the TextBox
<asp:TextBox id=’TextBox1′ dir=rtl runat=’server’></asp:TextBox>