Link to home
Start Free TrialLog in
Avatar of Sir Learnalot
Sir Learnalot

asked on

Button not working - launching a webpage from a button in C#

Hello Everyone, I made a form (WPF User Control) with a textbox called Tracking_Num, a comboBox called Courier_List, and a button called Tracking_Button. The idea is the user selects a courier, enters the tracking number, and hits track to launch the default browser and track the package using the provided courier and tracking #.
 
The button is completely not working - nothing happens when I click it not even an error.
 
Here is my XML code:
<ComboBox x:Name="Courier_List" Margin="102,363.711,83,125.874" ItemsSource="{Binding Path=Courier_List, Mode=Default, UpdateSourceTrigger=PropertyChanged}" >
        <ComboBoxItem x:Name="UPS" Content="UPS"/>
        <ComboBoxItem x:Name="FedEX" Content="FedEX"/>
        <ComboBoxItem x:Name="UPS_SCS" Content="UPS SCS"/>
</ComboBox>
 
<TextBox x:Name="Tracking_Num" Margin="102,393.2,83,96.237" Text="{Binding Path=Tracking_Num, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
 
<Button x:Name="Tracking_Button" Content="Track!" HorizontalAlignment="Left" Margin="284.6,393.2,0,0" VerticalAlignment="Top" Width="75" Height="24.8" Click="Tracking_Button_Click">

Open in new window


Here is my C# code:
<ComboBox x:Name="Courier_List" Margin="102,363.711,83,125.874" ItemsSource="{Binding Path=Courier_List, Mode=Default, UpdateSourceTrigger=PropertyChanged}" >
        <ComboBoxItem x:Name="UPS" Content="UPS"/>
        <ComboBoxItem x:Name="FedEX" Content="FedEX"/>
        <ComboBoxItem x:Name="UPS_SCS" Content="UPS SCS"/>
</ComboBox>
 
<TextBox x:Name="Tracking_Num" Margin="102,393.2,83,96.237" Text="{Binding Path=Tracking_Num, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
 
<Button x:Name="Tracking_Button" Content="Track!" HorizontalAlignment="Left" Margin="284.6,393.2,0,0" VerticalAlignment="Top" Width="75" Height="24.8" Click="Tracking_Button_Click">

Open in new window

SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sir Learnalot
Sir Learnalot

ASKER

My mistake. Here is my C# Code.

I was already using the System.Diagnostics.Process.STart(URL) method but it wasn't working so the first option there has IExplore.exe just for debug purposes (not that it helped).


private void Tracking_Button_Click(object sender, RoutedEventArgs e)
        {

            switch (Courier_List.SelectedValue.ToString())
            {
                case "UPS":

                    System.Diagnostics.Process.Start("IExplore.exe", "http://wwwapps.ups.com/ietracking/tracking.cgi?loc=CA_CA^&tracknum^=" + Tracking_Num.Text.ToString());
                    break;

                case "FedEX":
                    System.Diagnostics.Process.Start("https://www.fedex.com/fedextrack/index.html?tracknumbers^=" + Tracking_Num.Text.ToString() + "^&locale=en_CA^&cntry_code=ca_english");
                    break;

                case "UPS_SCS":
                    System.Diagnostics.Process.Start("https://www.upspostsaleslogistics.com/cfw/trackOrder.do?trackNumber^=" + Tracking_Num.Text.ToString());
                    break;

                default:
                    break;
            }
        }

Open in new window

try the navigation window.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Per https://www.experts-exchange.com/questions/28541134/Button-not-working-launching-a-webpage-from-a-button-in-C.html?anchorAnswerId=40393251#a40393251  the suggestion was to first format the URL and then call the System.Diagnostics.Process.Start.  

Since the code hasn't changed much I can only assume the issue was with how the URL was being formatted.  Had you had used the the https://google.com as an example you would have seen it was an issue with the URL.  I believe full points should be warranted for this.
@Kyle

1. The way the points system is setup, I can't recant the points I awarded (as far as I am aware).

2. If you read the posts thoroughly, you would have discovered I had already been using that format for my strings... I even explicitly said it in my post. The problem was not the format of the URL at all actually, had you read my solution you would realize I used SelectedIndex instead of SelectedValue, and changed the case to match the index # instead of looking for a string match...

3. Your answers literally helped me 0%. I actually requested attention on the topic because it was clear to me the answers were not pointing in the right direction... I had a hunch the problem was in the passing of the selection to the button handler... and I was correct. The only reason I gave you points is for effort, because you took the time to reply to my post. 250 points is more than generous.

I am sorry that you are not pleased with how I marked the solution, I hope that my explanation gave you some insight as to why it was awarded the way it was.

Have a great day and enjoy the rest of your week :)
I have provided points for effort but my solution was done completely independently. Thanks for all your efforts!