0

I'm looking to get 4 buttons which all lead to the same page. But depending on which button was chosen the contents of a query in that destination page is different.

So for example lets say that the buttons are named "button1" "button2" "button3" and "button4". These buttons are located on a page called TitlePage.xaml.

Then all the buttons navigate to a page called MainPage.xaml and within the code of this page is this piece of code

var qry = "/tblChemicals?$filter = " + (here is where i want to reference the button clicked) +" eq '" + Search.Text +"'";

So if button one was clicked the string would actuall read

var qry = "/tblChemicals?$filter = button1 eq '" + Search.Text +"'";

Here is the XAML code where the buttons are defined

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Button x:Name="Button1" Content="Button1" Height="72" HorizontalAlignment="Left" Margin="143,6,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
        <Button x:Name="Button2" Content="Button2" Height="72" HorizontalAlignment="Left" Margin="143,6,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
        <Button x:Name="Button3" Content="Button3" Height="72" HorizontalAlignment="Left" Margin="143,6,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
        <Button x:Name="Button4" Content="Button4" Height="72" HorizontalAlignment="Left" Margin="143,6,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
    </Grid>

2 Answers 2

0

What you need is creating a event in TitlePage.xaml.cs and subscribe to it in Main.xaml.cs. Then raise the event in the button clicked event handler.

Details can be found at: http://msdn.microsoft.com/en-us/library/w369ty8x.aspx

0

Looking at your code I would say your almost there..

 var qry = "/tblChemicals.xaml?$filter = " + (here is where i want to reference the button clicked) +" eq '" + Search.Text +"'"; 
 // Now you can do something like this
 NavigationService.Navigate(qry);

In your page you need to read the querystring back. (There's probably a better way to do this... but here's some sloppy code from one of my apps "OnNavigatedTo" event:

 var qry = NavigationService.CurrentSource.ToString().Split('?')[1];

That's it. Be sure to mark me as the answer if you think I have resolved your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.