Saturday, October 8, 2011

Access web control on Nested master page from content page

For example I have a DropDownList control in the inner master page. This control can be accessed from the content page in 2 ways.

  1. Using the findcontrol method to access the DropDownList, you need to use the DropDownList's ClientID.

    For example :

    DropDownList list = (DropDownList)this.Master.FindControl("ctl00$ctl00$ContentPlaceHolder1$DropDownList1");

  2. Expose the DropDownList control in the inner master page's code bhind, then the control can accessed directly.
    • Expose the DropDownList control:

        public DropDownList list
        {
             get
             {
                    return this.DropDownList1;
             }
        }

 

  • Add the masterType for the content page to strong type the master page:

    <%@ MasterType VirtualPath="~/Masterpage/NestMasterPage/MasterPage2.master" %>

     

  • Access the DropDownList in the content page's codebehind:

            DropDownList list = this.Master.list;

Happy Coding…

Wednesday, August 17, 2011

IDENT_CURRENT–Retrieve last inserted identity of record

SELECT IDENT_CURRENT(‘<tablename>’)


It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.

Happy Coding…

Tuesday, June 7, 2011

Simulating ListView’s ItemCommand Event

Data controls in asp.net like GridView, DataList, Repeater, ListView,… are having an event called ItemCommand.

This event will raise whenever any button, linkbutton,… are clicked.

But my requirement is to call the ItemCommand event whenever the ListView.Databind() is done.

Below is the procedure I followed for that.

System.Web.UI.WebControls.LinkButton lnkbtn = (System.Web.UI.WebControls.LinkButton)lvMyAlbums.Items[0].FindControl("lnkAlbum");

            ListViewCommandEventArgs ev = new ListViewCommandEventArgs(lvMyAlbums.Items[0], lnkbtn, new CommandEventArgs(lnkbtn.CommandName, lnkbtn.CommandArgument));

            // Call ItemCommand handler

            lvMyAlbums_OnItemCommand(lvMyAlbums, ev);

 

Happy coding…