You must Sign In to post a response.
  • Category: ASP.NET

    Post back Issue of Master Page

    Hello ,

    I have a master page having one label control.The Text value of control is set dynamically(ie from db). I am checking is post back also But this code is executing when we click on each page. i need to execute this this only one time. If lot of controls are there, then it not good to use session variable.Please help me.

    The code is as follows:

    If Not IsPostBack Then

    Dim objMasterBAL As New MasterBAL
    Dim dT As DataTable
    If Session("CompanyId") Is Nothing Then
    dT = objMasterBAL.SelectCompanyDetails(IIf(Session("CompanyId") Is Nothing, 1, Session("CompanyId")))
    lblCompanyName.Text = dT.Rows(0).Item("CompanyName").ToString
    Page.Header.Title = "::" & dT.Rows(0).Item("CompanyName").ToString
    End If

    end if
  • #766563
    I am not clear about this question. Following are some of the tips to related to your issue.

    1. If you want to use it only one time( ie on post back do not want to use it) check Page.IsPostback.
    2. If you want to use that for all the times (ie after postback also you want that values) do not check the postback

    Either you can use the Sessions or you can make the DB call again. Are you feeling DB call will cause performance issue?. If it is simple data retrieve you can use that. Other wise use the "Session". Why you want to go for other solutions?

    By Nathan
    Direction is important than speed

  • #766564
    I am not clear about this question. Following are some of the tips to related to your issue.

    1. If you want to use it only one time( ie on post back do not want to use it) check Page.IsPostback.
    2. If you want to use that for all the times (ie after postback also you want that values) do not check the postback

    Either you can use the Sessions or you can make the DB call again. Are you feeling DB call will cause performance issue?. If it is simple data retrieve you can use that. Other wise use the "Session". Why you want to go for other solutions?

    By Nathan
    Direction is important than speed

  • #766567
    Apparently it is not possible to have 2 pageLoad functions - one in the masterpage and one in the content page. The solution suggested there is making another function on the content page and call it if it exist:

    function pageLoad() {
    // Master pageLoad() code.

    // If function contentPageLoad exists, execute it.
    if(typeof contentPageLoad == 'function')
    contentPageLoad();
    }

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #766568
    Hi,

    I think you might call this master page on each page, whenever you call, it consider as a new request and reload the page again, i.e. for new request it moves to inside postback, that is the reason it loads again.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #766573
    Hello Nathan,

    I have some link buttons and some more lables are there in master page. I think it will affect the peformance of the application if we use session variable or calll db again and again. Thi controls are common to all content pages.

  • #766865
    check with a boolean value with session the first time it enters in to page

    if(session("already entered")!=null)
    {
    If Not IsPostBack && session("already entered") =false)
    {
    session("already entred") =true;
    }
    }

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI


Sign In to post your comments