How to refresh Web Usercontrol on button click - c#

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

Related

How to disable Master page in MasterDetailPage of Xamarin Forms

I am working with Xamarin forms and I need to disable the Master page that I use as context menu depending on whether user is logged in or not. I have both Master and Detail pages as separate XAML pages.
<MasterDetailPage.Master>
<view:MenuPage/>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<view:MainViewPage
x:Name="MainView"/>
</MasterDetailPage.Detail>
As you might have guessed, I am trying to incorporate MVVM here, so I tried binding visibility (IsVisible) and enabled (IsEnabled) properties of the Master page, however, I still get the undesired black fade effect when pushing navigation button to access my menu. Instead, I need to completely eat up the button press action.
Should your pages be visible whenever the user is connected or not ?
Or do you have a login page at the start of the application for example ?
If you don't have pages that are visible by both connected users or not, you could implement the login page or another page by defining it as ContentPage. It will take all the screen space and hide the navigationBar.
Then after user connect you call a page as MasterDetailPage and then you will have your navigationBar, ...
Don't know if that's what you're looking for but i hope i was able to help you.
This can be achieved with a custom NavigationRenderer, by overriding the Click event of the drawer icon with your custom logic.
[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomNavigationPageRenderer))]
namespace RTW.Mobile.App.Droid.Renderers
{
public class CustomNavigationPageRenderer : NavigationPageRenderer, IMessageSender
{
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
for (var i = 0; i < toolbar.ChildCount; i++)
{
var imageButton = toolbar.GetChildAt(i) as ImageButton;
var drawerArrow = imageButton?.Drawable as DrawerArrowDrawable;
if (drawerArrow == null)
continue;
//ensure only one handler is registered
imageButton.Click -= imageButton_Click;
imageButton.Click += imageButton_Click;
}
}
private void imageButton_Click(object sender, EventArgs e)
{
if (!App.IsBlockingConditionTrue)
{
MessagingCenter.Send<IMessageSender>(this, "ToggleMasterIsPresented");
}
}
}
}
Then just subscribe to the message with
MessagingCenter.Subscribe<IMessageSender>(this, "ToggleMasterIsPresented", OnToggleMasterIsPresented);
and handle it.
private void OnToggleMasterIsPresented(IMessageSender obj)
{
_masterDetailPage.IsPresented = !_masterDetailPage.IsPresented;
}

Using events of dynamically created buttons to redirect to another page ASP.NET

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.

Different functionalities of button[] at each click on a particular button

I have an array of button created dynamically, suppose 8 buttons, what I want is that when I click a particular button its background picture is changed and the name of button is stored in a linked list. When I click the same button again the background picture goes back to the original and the button name is deleted from linked list. Now I am able to do the first part, the second click is not working as I want it to.
Basically it's a datastructures project (shopping store) therefore I am using linked list, I have a linked list whose content is displayed through picture boxes[] and labels. Here what i am trying to do is when I click the picture box, the content of that particular node is added to a new linked list (added to the cart) and when I click on the picturebox again that particular item is deleted from the linked list (removed from the cart). Clicking it for the first time it is doing what i want it to do but the second click is not really working.
It's a datastructures project therefore I can't really use any built in classes for linked list, I had to write all methods myself and I did and they work.
cb[i].Click += (sender, e)=>{
if (flag == 0) {
// Console.WriteLine(obj.Retrieve(index).NodeContent);
// Console.WriteLine(obj.Retrieve(index).number);
inv.Add(obj.Retrieve(index).NodeContent, obj.Retrieve(index).number);
bill += Convert.ToInt32(obj.Retrieve(index).number);
cb[index].Image = Image.FromFile(#"F:\uni work\3rd semester\project images\rcart.jpg");
flag++;
}
else if (flag == 1)
{
// Console.WriteLine(bill);
bill -= Convert.ToInt32(obj.Retrieve(index).number);
// Console.WriteLine(bill);
inv.Delete(index);
cb[index].Image = Image.FromFile(#"F:\uni work\3rd semester\project images\cart.png");
flag--;
}
Since you are using a LinkedList it does have a Contains Method and a Remove Method that take a string. You haven't specified exactly what your problem is this should work. When you assign images to a control you loose the information that tells you what Image it is.
public partial class Form1 : Form
{
LinkedList<String> myList = new LinkedList<String>();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 8; i++)
{
Button b = new Button() { Height = 30, Width = 70, Location = new Point(i, 50 * i),Name = "NewButton" + (i + 1).ToString() , Tag=i};
b.Click += b_Click;
this.Controls.Add(b);
}
}
void b_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
if(myList.Contains(b.Name)) //Check if button is in the List then Change Picture and remove
{
b.BackgroundImage = Properties.Resources.Peg_Blue;
myList.Remove(b.Name);
}
else
{
b.BackgroundImage = Properties.Resources.Peg_Red;
myList.AddLast(b.Name);
}
}
}
Why not create a class for each button, containing the two images and switch between them on each click?

how to do task after xaml page is loaded in windows phone

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.

wp8: open htm page in webBrowser by button click?

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.

Categories

Resources