For some reason, the Page_PreRenderComplete() is not firing for me in a user web control. Here is my code behind, any ideas why?
public partial class Views_CMSWebParts_GSAMetaTags : System.Web.UI.UserControl
{
public string Content { get; set; }
public string LastModifiedDate { get; set; }
public string PageTitle { get; set; }
public string PageDescription { get; set; }
protected void Page_PreRenderComplete(object sender, EventArgs e)
{
if (CMSContext.CurrentDocument.NodeClassName.Equals("ctv.DailyContent")
|| CMSContext.CurrentDocument.NodeClassName.Equals("ctv.Segment")
|| CMSContext.CurrentDocument.NodeClassName.Equals("ctv.segmentContainer"))
{
Content = "news-and-articles";
//Published Date
LastModifiedDate = ValidationHelper.GetString(CMSContext.CurrentDocument.GetValue("DocumentModifiedWhen"), "");
PageTitle = CMSContext.CurrentPageInfo.DocumentPageTitle;
PageDescription = CMSContext.CurrentPageInfo.DocumentPageDescription;
}else if (CMSContext.CurrentDocument.DocumentName.Equals("Video"))
{
//using document name in this case becuase Video page type is Page (menu item)
Content = "video";
}
}
}
I don't think a UserControl has a PreRenderComplete event. A Page does, but not a UserControl. A UserControl does have a PreRender event, as well as a Render event. You can use it like this:
protected void Page_Load(object sender, EventArgs e)
{
this.PreRender += new EventHandler([method name]);
}
Related
I created a custom picker with the help of Lucas Zhang which you can check in the link
xamarin custom multiple picker
Now I have another question with this problem. When user select a group or groups, I need access to these selected parameters.
public class Grup
{
public int ID { get; set; }
public string GroupName { get; set; }
public Nullable<int> SubsID { get; set; }
}
This is the model I use. Picker reads Groupnames through ViewModel which is shown below.
public class NewUserViewModel
{
public List<Grup> GroupList { get; set; }
public List<Grup> SelectedGroup { get; set; }
}
And I want save these parameters which came from every pickers in the view to here and furthermore I will send them to database through API.Question is how can I access these IDs when user select them and click save button.
An easy way to do this is to listen for picker's selection events and then get the result of each selection by iterating over the pickerStack
like this(base on Lucas Zhang's sample):
in PickerView :
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class PickerView : ContentView
{
public Group SelectGroup; // add the SelectGroup property which save the result after you select
public ObservableCollection<Group> pickerSource { get; set; }
public PickerView(ObservableCollection<Group> source) //here i change the source to your Group model
{
InitializeComponent();
picker.ItemsSource = source;
}
private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
var stack = this.Parent as StackLayout;
stack.Children.Remove(this);
}
private void picker_SelectedIndexChanged(object sender, EventArgs e)
{
var picker = sender as Picker;
SelectGroup = (Group)picker.SelectedItem;
}
}
in PickerView.xaml just add the SelectedIndexChanged event:
<Picker Grid.Column="0" x:Name="picker" Title="{Binding GroupName}" ItemDisplayBinding="{Binding ID}" TitleColor="Red" SelectedIndexChanged="picker_SelectedIndexChanged" />
in your page :
public partial class MutiPicker : ContentPage
{
public MutiPicker()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
var source = new ObservableCollection<Group>() { new Group() { ID=111,GroupName="AAA",SubsID=1}, new Group() { ID = 222, GroupName = "BBB", SubsID = 2 }, new Group() { ID = 333, GroupName = "CCC", SubsID = 3 } };
pickerStack.Children.Add(new PickerView(source));
}
//iterate over your pickerviews
private void Update_Clicker(object sender, EventArgs e)
{
foreach (var pickerview in pickerStack.Children)
{
if (pickerview is PickerView && ((PickerView)pickerview).SelectGroup != null)
{
var selectgroup = ((PickerView)pickerview).SelectGroup;//here you will get your select group,then you could get its ID ,GroupName or SubsID
}
}
}
}
Class Icons.cs:
public class Icon
{
public int IconID { get; set; }
public string Title { get; set; }
public string Room { get; set; }
public string ImageCover { get; set; }
}
public class IconManager
{
public static List<Icon> GetIcons()
{
var Icons = new List<Icon>();
Icons.Add(new Icon { IconID = 1, Title = "Mr.Ha", Room = "611-Room", ImageCover = "Assets/Ha.jpg" });
Icons.Add(new Icon { IconID = 2, Title = "Mr.Synh", Room = "611-Room", ImageCover = "Assets/Synh.jpg" });
return Icons;
}
}
Class MainPage:
public MainPage()
{
this.NavigationCacheMode = NavigationCacheMode.Enabled;
this.InitializeComponent();
Icons = IconManager.GetIcons();
}
private void ForegroundElement_ItemClick(object sender, ItemClickEventArgs e)
{
var icon = (Icon)e.ClickedItem;
var tittle = icon.Title;
ForegroundElement.PrepareConnectedAnimation("ca1", icon, "ConnectedElement");
switch (tittle)
{
case "Mr.Ha":
Frame.Navigate(typeof(BlankPage1));
break;
}
}
private async void ForegroundElement_Loaded(object sender, RoutedEventArgs e)
{
if(Icons != null)
{
ForegroundElement.ScrollIntoView(Icons, ScrollIntoViewAlignment.Default);
ForegroundElement.UpdateLayout();
ConnectedAnimation animation = ConnectedAnimationService.GetForCurrentView().GetAnimation("ca2");
if (animation != null)
{
await ForegroundElement.TryStartConnectedAnimationAsync(
animation, Icons, "ConnectedElement");
}
}
Class BlankPage1:
public BlankPage1()
{
this.NavigationCacheMode = NavigationCacheMode.Enabled;
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
ConnectedAnimation imageAnimation = ConnectedAnimationService.GetForCurrentView().GetAnimation("ca1");
if (imageAnimation != null)
{
imageAnimation.TryStart(TargetElement);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("ca2", TargetElement);
Frame.Navigate(typeof(MainPage));
}
There something wrong with my Animation when I "Navigate Back" to the MainPage. The picture just stay still there then it's disappear, while the listview is done loaded !!My navigation from MainPage to BlankPage1 is fine though!!
Your second connected animation is called ca2, but you are using ca1 in the MainPage's ForegroundElement_Loaded event handler. Because of this, the animation cannot be connected, which results in the behavior you are seeing.
I created a Windows phone 8.1 application with a listview on Startpage.xaml. When I update listview values, I don't see the changes on the phone until I close and open the application again. I tried to update the listview when I clicked the refresh button, but unsuccessfully. Anyone know how to update a listview when I click the refresh button?
How I fill in data in the listview:
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
this.navigationHelper.OnNavigatedTo(e);
HttpClient http = new HttpClient();
string str = ((ComboBoxItem)cbox.SelectedItem).Content.ToString();
var response = await http.GetStringAsync("http://mywebpage.si/events/apis/facebook_events.php?city=" + str + "&user=" + uporabnik.user);
var FSfeed = JsonConvert.DeserializeObject<List<Class1>>(response);
Reviews.ItemsSource = FSfeed;
}
My class:
public class Class1
{
public string title { get; set; }
public string description { get; set; }
public string image { get; set; }
public string start { get; set; }
public string end { get; set; }
public string location { get; set; }
public string city { get; set; }
public int id { get; set; }
}
Refresh button:
private async void refresh_Click(object sender, RoutedEventArgs e)
{
HttpClient http = new HttpClient();
string str = ((ComboBoxItem)cbox.SelectedItem).Content.ToString();
var response = await http.GetStringAsync("http://mywebpage.si/events/apis/facebook_events.php?city=" + str + "&user=" + uporabnik.user);
var FSfeed = JsonConvert.DeserializeObject<List<Class1>>(response);
Reviews.ItemsSource = FSfeed;
}
I also tried to refresh like this, but unsuccessfully:
private async void refresh_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(PivotPage));
}
To update the view you need to update the binding to ItemSource:
List<Class1> mySource = new List<Class1>();
Binding binding = new Binding { Source = mySource };
BindingOperations.SetBinding(myListView, Windows.UI.Xaml.Controls.ListView.ItemsSourceProperty, binding);
I am a Final Year Computer Science student trying to develop a Windows 8 phone app and I am very new to this type of development.
I am using a Windows Azure account with a mobile service and a database connection to connect to Visual Studio 2012.
I am trying to allow users to create an account to use my app, however when they enter any details they are not being saved to the table in the database. I am getting the following debugging error when I run my code and press the register button:
"Application_UnhandledException"
Below is what my code looks like.
This is from the CreateAccount.xaml.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.WindowsAzure.MobileServices;
using Newtonsoft.Json;
namespace IME.Miscellaneous
{
public class accountDetails
{
// Setting up the items for inclusion in the createAccount table
public string Id { get; set; }
[JsonProperty(PropertyName = "userpassword")]
public string Password { get; set; }
[JsonProperty(PropertyName = "securityQuestion1")]
public string SecurityQuestion1 { get; set; }
[JsonProperty(PropertyName = "securityQuestion2")]
public string SecurityQuestion2 { get; set; }
[JsonProperty(PropertyName = "securityQuestion3")]
public string SecurityQuestion3 { get; set; }
[JsonProperty(PropertyName = "answer1")]
public string SecurityAnswer1 { get; set; }
[JsonProperty(PropertyName = "answer2")]
public string SecurityAnswer2 { get; set; }
[JsonProperty(PropertyName = "answer3")]
public string SecurityAnswer3 { get; set; }
}
public partial class CreateAccount : PhoneApplicationPage
{
private MobileServiceCollection<accountDetails, accountDetails> items;
private IMobileServiceTable<accountDetails> accountTable = App.MobileService.GetTable<accountDetails>();
public CreateAccount()
{
InitializeComponent();
}
private async void InsertAccountInfo(accountDetails accountDetailsItem)
{
// This code inserts a new item into the database. When the operation completes
// and Mobile Services has assigned an Id, the item is added
await accountTable.InsertAsync(accountDetailsItem);
items.Add(accountDetailsItem);
}
private async void RefreshAccountInfo()
{
// This code refreshes the entries in the list view be querying the createAccount table.
try
{
items = await accountTable
.Where(accountDetailsItem => accountDetailsItem.Password == "")
.ToCollectionAsync();
}
catch (MobileServiceInvalidOperationException e)
{
MessageBox.Show(e.Message, "Error loading items", MessageBoxButton.OK);
}
}
private void Register_Button_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
// Brings the user to the Home hub page
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
// When button is clicked the accountDetails table is updated with the password
//var user = new accountDetails { Id = ID_textbox.Text, Password = Password_Text.Password, SecurityQuestion1 = Security_Question_1.Text, SecurityQuestion2 = Security_Question_2.Text,
// SecurityQuestion3 = Security_Question_3.Text, SecurityAnswer1 = Security_Question_1_Answer.Text, SecurityAnswer2 = Security_Question_2_Answer.Text,
// SecurityAnswer3 = Security_Question_3_Answer.Text};
// InsertAccountInfo(user);
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
RefreshAccountInfo();
}
private void Security_Question_1_Answer_GotFocus(object sender, RoutedEventArgs e)
{
// Sets the textbox to empty when the user clicks on it
TextBox securityAnswerOne = (TextBox)sender;
securityAnswerOne.Text = string.Empty;
securityAnswerOne.GotFocus -= Security_Question_1_Answer_GotFocus;
}
private void Security_Question_2_Answer_GotFocus(object sender, RoutedEventArgs e)
{
// Sets the textbox to empty when the user clicks on it
TextBox securityAnswerTwo = (TextBox)sender;
securityAnswerTwo.Text = string.Empty;
securityAnswerTwo.GotFocus -= Security_Question_2_Answer_GotFocus;
}
private void Security_Question_3_Answer_GotFocus(object sender, RoutedEventArgs e)
{
// Sets the textbox to empty when the user clicks on it
TextBox securityAnswerThree = (TextBox)sender;
securityAnswerThree.Text = string.Empty;
securityAnswerThree.GotFocus -= Security_Question_3_Answer_GotFocus;
}
private void Security_Question_3_Answer_LostFocus(object sender, RoutedEventArgs e)
{
TextBox securityAnswerThree = (TextBox)sender;
if (String.IsNullOrEmpty(Security_Question_3_Answer.Text))
{
securityAnswerThree.Text = "Please Enter an answer";
securityAnswerThree.LostFocus -= Security_Question_3_Answer_LostFocus;
}
}
private void Security_Question_2_Answer_LostFocus(object sender, RoutedEventArgs e)
{
TextBox securityAnswerTwo = (TextBox)sender;
if (String.IsNullOrEmpty(Security_Question_2_Answer.Text))
{
securityAnswerTwo.Text = "Please Enter an answer";
securityAnswerTwo.LostFocus -= Security_Question_2_Answer_LostFocus;
}
}
private void Security_Question_1_Answer_LostFocus(object sender, RoutedEventArgs e)
{
TextBox securityAnswerOne = (TextBox)sender;
if (String.IsNullOrEmpty(Security_Question_3_Answer.Text))
{
securityAnswerOne.Text = "Please Enter an answer";
securityAnswerOne.LostFocus -= Security_Question_3_Answer_LostFocus;
}
}
}
}
This is from the App.xaml.cs file:
// Creating account details table
public class accountDetails
{
public int id { get; set; }
public string userpassword { get; set; }
public string securityQuestion1 { get; set; }
public string securityQuestion2 { get; set; }
public string securityQuestion3 { get; set; }
public string answer1 { get; set; }
public string answer2 { get; set; }
public string answer3 { get; set; }
public accountDetails(string p, string sq1, string sq2, string sq3, string a1, string a2, string a3)
{
// Creating the constructor
userpassword = p;
securityQuestion1 = sq1;
securityQuestion2 = sq2;
securityQuestion3 = sq3;
answer1 = a1;
answer2 = a2;
answer3 = a3;
}
}
The table in the database is called "CreateAccount" also.
Any help would be greatly appreciated.
I have a property Grid as follows:
I want to copy the complete content of the property grid to a data grid view(dataGeriView1) when submit button is clicked.
How to do this?
Please help.
private void Submit_Click(object sender, EventArgs e)
{
//propertyGrid1.SelectedObject = this;
dataGridView1.Columns.Add("Property", "Property");
dataGridView1.Columns.Add("Value", "Value");
GridItem gi = propertyGrid1.SelectedGridItem;
while (gi.Parent != null)
gi = gi.Parent;
foreach (GridItem item in gi.GridItems)
ParseGridItems(item); //recursive
dataGridView1.Sort(dataGridView1.Columns["Property"], ListSortDirection.Ascending);
}
private void ParseGridItems(GridItem gi)
{
if (gi.GridItemType == GridItemType.Category)
foreach (GridItem item in gi.GridItems)
ParseGridItems(item);
dataGridView1.Rows.Add(gi.Label, gi.Value);
}
Adapted from https://stackoverflow.com/a/12109186/1163434
Below is a sample snippet i have created to solve the above issue. Create a DataGridview by adding Columns Name,Age,Email,Phone.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Student std = new Student {Name = "Vimal" , Phone = "PhoneValue", Email="mymail",Age=24};
propertyGrid1.SelectedObject= std;
}
private void button1_Click(object sender, EventArgs e)
{
int index = dataGridView1.Rows.Count - 1;
Student std = (Student)propertyGrid1.SelectedObject;
dataGridView1.Rows[index].Cells["Name"].Value = std.Name;
dataGridView1.Rows[index].Cells["Age"].Value = std.Age;
dataGridView1.Rows[index].Cells["Email"].Value = std.Email;
dataGridView1.Rows[index].Cells["Phone"].Value = std.Phone;
}
}
public class Student
{
public int Age { get; set; }
public string Email { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
}