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 4575468
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:04:04+00:00 2026-05-21T20:04:04+00:00

So at the moment my page is currently working with the following code in

  • 0

So at the moment my page is currently working with the following code in my cs file. What I need to change is to add an event handler so that when a button is clicked the MainPage_Loaded happens only after this button is clicked.

I understand that the line

this.Loaded += new RoutedEventHandler(MainPage_Loaded);

is currently calling this method to start but when I try and put this code into the button1_click event handler it does not work.

  public MainPage()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(MainPage_Loaded);     
    }

    public void button1_Click(object sender, RoutedEventArgs e)
    {


    }

    private void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        var ctx = new HazchemEntities(new Uri("http://devweb.compsci.chester.ac.uk/0808092/CO6009/HazchemService.svc/"));
        App.coll = new DataServiceCollection<tblChemical>(ctx);
        Lst.ItemsSource = App.coll;

        App.coll.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(coll_LoadCompleted);

        var qry = "/tblChemicals?$filter UNNumber = eq'" + Search.Text + "'";
        App.coll.LoadAsync(new Uri(qry, UriKind.Relative));

        if (!App.ViewModel.IsDataLoaded)
        {
            App.ViewModel.LoadData();
        }


   }

Here is the XAML code that I am using.

    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        <TextBox x:Name="Search"  Height="72" Margin="-4,0,50,0" Text="TextBox" VerticalAlignment="Top" Width="350" HorizontalAlignment="Left"/>
        <Button Content="Go" Height="72" HorizontalAlignment="Left" Margin="350,0,0,0" Name="button1" VerticalAlignment="Top" Width="100" Click="button1_Click" />

    </StackPanel>

What do I need to put into the button1_Click event to make it start the mainpage_loaded only when this button is clicked?

Thanks

  • 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-21T20:04:05+00:00Added an answer on May 21, 2026 at 8:04 pm

    You seem to have misunderstood something… This line:

    this.Loaded += new RoutedEventHandler(MainPage_Loaded);

    is not causing the void MainPage_Loaded(object sender, RoutedEventArgs e) function to be called immediately. It is registering a handler for that event – when the MainPage has finished loading it internally fires the Loaded event, in turn the event handler gets called.

    Setting up that handler in the button1_Click also makes no sense – your page has already well and truly loaded by the time a button can be clicked.

    If you have some functionality in the MainPage_Loaded function that you want the button1_Click to also use then you should refactor it out into a separate function that they can both call.

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

Sidebar

Related Questions

At the moment I'm adding elements to a page on a click event using
I am currently working on a site that is being built on codeigniter, I
I had to change some code that was created by another person in VS2008,
After working on a page for quite some time, the customer now decided that
I am currently working on a private project that is going to use Google's
I've got a script that binds to the keyup event as a page is
At the moment I am trying to create a setup where page content is
Folks, I'm tryning to extract data from web page using C#.. for the moment
At the moment my code (PHP) has too many SQL queries in it. eg...
My team is currently working on a substantial update to an existing ASP.NET 3.5

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.