Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7633571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:55:21+00:00 2026-05-31T06:55:21+00:00

me again, I have a current page containing a usercontrol which lists buildings. Here

  • 0

me again,

I have a current page containing a usercontrol which lists buildings.

Here is a screenshot: http://i40.tinypic.com/2eusoyt.png

Now, my mentor asked me to build a button which allows the user the make the page show the properties in 2 columns.

How did I try this?
I tried putting the following in my Page_load:

            if (ViewState["numberOfColumns"] != null)
            {
                numberOfColumns= Int32.Parse(ViewState["numberOfColumns"].ToString());

            }
            else
            {
                ViewState["numberOfColumns"] = 1;
                numberOfColumns= 1;
            }

Then behind the button view I put this code:

        protected void btnView_Click(object sender, EventArgs e)
    {
        switch(numberOfColumns)
        {
            case 1:
                numberOfColumns= 2;
                ViewState["numberOfColumns"] = numberOfColumns;

                break;
            case 2:
                numberOfColumns= 1;
                ViewState["numberOfColumns"] = numberOfColumns;
                break;
        }

    }

But as I guessed this method needs one postback to set the sessionvariable, and another one to execute the pageload with the latest value.

I know there should be “a proper way” of doing this, but I can’t find it.

Any direct you guys could point me would be greatly appreciated.

Thanks in advance, Christophe

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:55:23+00:00Added an answer on May 31, 2026 at 6:55 am

    Okay,

    This is how I did it.

    The method building the output of the user control was called directly after the snippet above. It’s called “GetProperties()”.

    So the problem was/is that according to the page cycle, .net first executes the Page_Load, and as last the control events.

    So what I did was put the call to getProperties() for the first time (when IsPostback = false) in an if. So when you visit the page once, it will load the method, and after that no longer.

    So, then I put the methodcall in my button, because when you click the button IsPostback = true.

    This worked. Snippets below:
    protected void Page_Load(object sender, EventArgs e)
    {
    //some generic stuff

                if (!IsPostBack)
                {
                    ViewState["kolommen"] = 1;
                    AantalKolommen = 1;
                    GetProperties(_tkth, _categorie, _verkochtverhuurd);
                }
            }
    

    And behind the button I did the following:

            protected void btnView_Click(object sender, EventArgs e)
        {
            switch (Int32.Parse(ViewState["kolommen"].ToString()))
            {
                case 1:
                    AantalKolommen = 2;
                    ViewState["kolommen"] = 2;
                    break;
                case 2:
                    AantalKolommen = 1;
                    ViewState["kolommen"] = 1;
                    break;
            }
            GetProperties(_tkth, _categorie, _verkochtverhuurd);
        }
    

    This works like a charm. Altho, I’d still like to know if this

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Again I have a question regarding this plugin: http://t.wits.sg/2008/06/20/jquery-progress-bar-11/ What I want to achieve
Me again... I have an XML File that contains different categories which I would
I have a Canvas which has many components inside it and those again, have
This time I have an error which I have been trying again to figure
I have written the following jQuery for autorefreshing a page containing a poll (to
I have a page which uses a the hash # to store some extra
Here is my situation. I have a web page for users to create their
I have a page which submits a form on page load and redirects the
I have two div tags - current page appears like ------------- <tag-1> <tag-2> ---------------
I have a page in which one chooses from a selection of dynamically generated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.