I have several html pages in my app. I named those html files as f1.html, f2.html, f3.html, \... f454.html. So, I want to display these files by user preference. So, I have created a textbox and button in CustomMessageBox using NuGet and an xaml page with the name webview.xaml. If user entered 3 in the textbox, f3.html should be open in webview.xaml.
I don't know how to code. Best answer will much appreciated seriously.
C# Code I did til now [UPDATE];
TextBox getFileNo = new TextBox();
getFileNo.Height = 72;
getFileNo.Width = 150;
getFileNo.MaxLength = 3;
TextBox getHashNo = new TextBox();
getHashNo.Height = 72;
getHashNo.Width = 150;
getHashNo.MaxLength = 3;
string showFile;
showFile = getFileNo.Text;
string hashId;
hashId = getHashNo.text;
NavigationService.Navigate(new Uri("/webview.xaml?Page=" + site, UriKind.Relative));
In webview.xaml:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationContext.QueryString.ContainsKey("Page"))
{
var page = NavigationContext.QueryString["Page"];
browser.Navigate(new Uri("/f" + page + ".html#" + hashId, UriKind.Relative));
}
}
You can navigate to the webview.xaml page passing it querystring with the desired hmtl file:
NavigationService.Navigate(new Uri(String.Format("/webview.xaml?Page={0}&id={1}", showFile, hashId), UriKind.Relative));
In your webview.xaml page, you can override OnNavigatedTo method to check the passed page and open it in web browser:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationContext.QueryString.ContainsKey("Page") && NavigationContext.QueryString.ContainsKey("id"))
{
var page = NavigationContext.QueryString["Page"];
var hashId = NavigationContext.QueryString["id"];
yourWebBrowser.Navigate(new Uri(String.Format("/f{0}.html#{1}", page, hashId), UriKind.Relative));
}
}
See Passing paramenters section from How to perform page navigation on Windows Phone for more information.
Related
I'm trying to call events of dynamically created buttons sending parameters, but when I click nothing happens, just Post Back the page.
public void adicionarComanda()
{
List<Comanda> lc = ControllerComanda.getComanda();
foreach (Comanda comanda in lc)
{
Button bt = new Button();
bt.Text = comanda.nome_Pessoa;
bt.CssClass = "botoes";
bt.Click += btnNome1_Click;
bt.CommandArgument = comanda.nome_Pessoa;
HtmlGenericControl li = new HtmlGenericControl("li");
li.Controls.Add(bt);
ulBotoes.Controls.Add(li);
}
}
And the Event
protected void btnNome1_Click(object sender, EventArgs e)
{
string nomePessoa = (sender as Button).CommandArgument;
Session["currentUser"] = nomePessoa.ToString();
Response.Redirect("~/Mobile/Pages/produtosCategoria.aspx");
}
But nothing Happens when I click the button, just PostBack the page. How can I fix this problem?
Thank you guys
You need to re-render all dynamically generated controls on every postback. I suggest creating a method that generates the these controls then call that method on every postback in Page_Load.
Have you thought about maybe passing "currentuser" as a parameter? bt.Attributes.Add("onclick", "javascript:redirect('~/Mobile/Pages/produtosCategoria.aspx?name=comanda.nome_Pessoa')";
Instead of defining click function you can use another approach - PostBackUrl.
public void adicionarComanda()
{
List<Comanda> lc = ControllerComanda.getComanda();
foreach (Comanda comanda in lc)
{
Button bt = new Button();
bt.Text = comanda.nome_Pessoa;
bt.CssClass = "botoes";
bt.PostBackUrl = String.Format("~/Mobile/Pages/produtosCategoria.aspx?user={0}", comanda.nome_Pessoa);
HtmlGenericControl li = new HtmlGenericControl("li");
li.Controls.Add(bt);
ulBotoes.Controls.Add(li);
}
}
Then in the redirected page you can use Request.QueryString["user"] , and use it as required.
So I'm working on Windows Phone Project based on music shuffling. I have one xaml page that display Songs in Queue, code file contain List<> that add all song in list but this task take more time.
When i Click a Button to navigate(or show queue)to page my app still remain same page for 4-5 second.
I want that how can I make some code in xaml.cs file that run after page is loaded.
After page loaded I show Progress Indicator and when all data completely in List<> elements, I show a Songs.
My code:
private void Event()
{
currentQueueData = MediaPlayer.Queue;
List<QueueData> boundedQueueData = new List<QueueData>();
SetProIndicator(true);
SystemTray.ProgressIndicator.Text = "Loading...";
if (currentQueueData.Count != 0)
{
for (int i = currentQueueData.ActiveSongIndex, k = 0; i < totalqueueCount; i++)
{
loadedqueueSongs[k] = currentQueueData[i];
boundedQueueData.Add(new QueueData()
{
queueSongIndex = k++,
queueSongName = currentQueueData[i].Name,
queueSongAlbum = currentQueueData[i].Album.Name + ",",
queueSongArtist = " " + currentQueueData[i].Artist.Name,
});
}
queueList.ItemsSource = boundedQueueData;
SetProIndicator(false);
//queueList.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
}
else
{
boundedQueueData.Add(new QueueData()
{
queueSongIndex = 0,
queueSongName = "Currently Queue Is Empty",
queueSongAlbum = "",
queueSongArtist = "",
});
queueList.ItemsSource = boundedQueueData;
}
}
If it is Possible that Event() function load after MyPage.xaml page is loaded?
Following the comments on the question, one possible answer would be to suscribe to the Loaded event of your page and call the Event method from there.
Really simple example:
public MyPage()
{
this.Loaded += PageLoaded;
}
void PageLoaded(object sender, RoutedEventArgs e)
{
this.Event();
}
So what we did is to suscribe to the loaded event on the constructor of the page. By the time the page is loaded, you will be able to call your Event method from the callback.
I am in the process of making a multi tab browser and have run into some problems. I would like it so when the user has added a new tab using a button, that every site they then choose to navigate to will update to the tab url. So if the user changes tab or opens a new one, it the last website will be saved if they return to the previous tab.
Here is the code while creating a new tab & When a tab is selected from the created ones
private void addNewTab(string url)
{
TabEntry urlObj = new TabEntry();
urlObj.URL = url;
urlObj.timestamp = DateTime.Now.ToString("HH:mm");
if (url.Contains("/"))
{
urlObj.Name = url.Remove(url.IndexOf('/'));
}
else
{
urlObj.Name = url.Remove(url.IndexOf('.'));
}
tabs.Insert(0, urlObj);
listBoxTabPage.ItemsSource = null;
listBoxTabPage.ItemsSource = tabs;
Browser.Navigate(new Uri("http://www.google.com", UriKind.Absolute));
//selectedTab = listBoxTabPage.SelectedValue as TabEntry;
}
private void ListBoxTabPage_SelectionChanged(object sender, GestureEventArgs e)
{
selectedTab = listBoxTabPage.SelectedValue as TabEntry;
Browser.Navigate(new Uri("http://www." + selectedTab.URL, UriKind.Absolute));
PivotItems.SelectedItem = BrowserPage;
}
Here is the code where it should update the selected tabs url, in the Browser_Navigated methord
void Browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
_deactivatedURL = e.Uri;
_progressIndicator.IsVisible = false;
string url = Convert.ToString(e.Uri);
//selectedTab.URL = url;
addHistoryRecord(url);
}
Where it is commented out I think is the problem. I believe the code does not know which one is the selectedTab. To fix this error should I create a methord which updates the url of the tab, each time the browser navigates. And how would the program know which tab is currently in use.
If you need any more details please comment and I will be happy to explain in further detail.
You just set listBoxTabPage.ItemsSource = null before you set tabs as ItemsSource. It may clears your listBoxTabPage.SelectedValue.
I think you can just set listBoxTabPage.SelectedValue = urlObj in addNewTab().
Then you begin navigate to a new uri in ListBoxTabPage_SelectionChanged, but it seems to be wrong that you just append a prefix string http://www. to an full url. It may triggers NavigateFailed event if you navigate to a non-exist website.
Browser.Navigate(new Uri("http://www." + selectedTab.URL, UriKind.Absolute));
What's more, ListBoxTabPage_SelectionChanged may triggers twice because the old value is cleared and the new value is set.
I am using a web user control on an aspx page for displaying the locations on a google map into which I am passing locations as parameters from ASPX page load event and whenever the page is loaded I am getting the locations perfectly.
I have to change the locations whenever user searches for a particular location on clicking the "Search" button ion the ASPX page and i am passing the locations to web user control in the "search" button click event but unable to get the locations onto the web user control.
public partial class MapControl : System.Web.UI.UserControl
{
public List<string> MyLocation {get; set; }
protected void Page_Load(object sender, EventArgs e)
{
GeoCode geocode;
List<GMarker> markers = new List<GMarker>();
for (int i = 0; i < MyLocation.Count(); i++)
{
geocode = GMap1.getGeoCodeRequest(MyLocation[i]);
GLatLng gLatLng = new GLatLng(geocode.Placemark.coordinates.lat, geocode.Placemark.coordinates.lng);
GMap1.setCenter(gLatLng, 20, GMapType.GTypes.Normal);
GMarker oMarker = new GMarker(gLatLng);
markers.Add(oMarker);
//GMap1.Add(oMarker);
GListener listener = new GListener(oMarker.ID, GListener.Event.click, string.Format(#"function () {{ var w = new google.maps.InfoWindow(); w.setContent('<center>{0}</center>'); w.open({1}, {2});}}", "<b>" + MyLocation[i] + "</b>", GMap1.GMap_Id, oMarker.ID));
GMap1.Add(listener);
}
GMap1.Add(new GMapUI());
GMap1.GZoom = 10;
protected void Button1_Click1(object sender, EventArgs e)
{
List<string> locations = new List<string>();
for (int i = 0; i < ListView1.Items.Count; i++)
{
Label addressline1 = (Label)this.ListView1.Items[i].FindControl("addr1");
string addrloc = addressline1.Text;
locations.Add(addrloc);
}
MapControl mc = LoadControl("~/MapControl.ascx") as MapControl;
mc.MyLocation = locations;
}
And i included this web user control into Search.aspx file and and when i passed locations from page load event its working but when i tried to pass locations from search button click event getting Null value into Mylocations value of Web user control as null.. so Is there any way to to reload the User control with newer locations.
I think you can use here updatepanel. You have to keep google map into update panel and set trigger against this button to your map. Then I think you will get what you want. If any confusion pls let me know
I have a ReorderList which is working fine, inside the InsertItemTemplate, I've added a asp:Fileupload to add images to the list and database. All of these controls are inside a DIV.
How could I reach to this (asp:FileUpload) in C# to check whether it has a file or not,
this is the C# part of the code:
///////////////////////////////////////////////////////////////////////////////////////////////
protected void btnInsert_Click(object sender, EventArgs e)
{
string sFilename = Guid.NewGuid().ToString();
FileUpload filePhoto = (FileUpload)div1.FindControl("filePhoto");
if (filePhoto.HasFile)
{
string sPath = "";
string sFile = filePhoto.FileName.ToString();
sPath = Server.MapPath("Images");
filePhoto.SaveAs(sPath + "\\" + sFile);
//to fill the Notice image by code behine
ObjectDataSource1.InsertParameters["theImage"].DefaultValue = "Images\\" + sFile;
}
else
{
//to fill the Notice image by code behine
ObjectDataSource1.InsertParameters["theImage"].DefaultValue = "Images\\" + "NoImage.jpg";
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
any ideas?
Thanks in advance
Actually ReorderList is an ajax control and you cannot use normal Asp:Fileuploader in ajax control. You have to use the asyncfileuploader control of ajax control toolkit in order to work in ajax application.