I want to change control value exists in Master page from user control and the scenario is like this:
On user control load method I use a query string parameter called "catID" to get category entity, then I want to set the category title as value of title tag (Category title) ,which locate in Master page .
I tried to change the title in user control page load control but the Master page load method executes earlier.
Any ideas ?
Provide a public method in your MasterPage that sets the title, for example:
public void setTitle(string title)
{
this.LblTitle.Text = title;
}
Then you can call it from your UserControl(YourMasterPage is the actual type of the MasterPage):
((YourMasterPage)this.Page.Master).setTitle("new Title");
If it's a query string parameter you should be able to read "catId" i.e from Masterpage code behind as well and set the title.
EDIT:
Try a property then:
In usercontrol
protected void Page_Load(object sender, EventArgs e)
{
this.MyTitle = "SomeTitle";
}
public string MyTitle { get; set; }
On masterpage:
protected void Page_Load(object sender, EventArgs e)
{
WebUserControl.PreRender += new EventHandler(WebUserControl_PreRender);
}
void WebUserControl_PreRender(object sender, EventArgs e)
{
string str = WebUserControl.MyTitle;
this.Header.Title = str;
}
((Label)Master.FindControl("loadlbl")).Text = "your text";
Related
I'm trying to create a search box that leads to another page to execute the search. E.g. search in Inquirypage --> get result in Listpage. How do I get the value from Inquiry page to list page since they're not in the same class. Can i get some insights? Thank you
Search button from first page:
public async void FromBPSearchTap(object sender, EventArgs e)
{
var BPSearch = Customer.Text;
if (string.IsNullOrWhiteSpace(BPSearch))
{
BPSearch = string.Empty;
}
BPSearch = BPSearch.ToUpperInvariant();
}
Pass the string as a parameter to the next page's constructor.
Sample code as below:
In your InquiryPage.xaml.cs
private async void FromBPSearchTap(object sender, System.EventArgs e)
{
//...
//your code with BPSearch
await Navigation.PushAsync(new ListPage(BPSearch));
}
In your next ListPage.xaml.cs
string _searchText
public ListPage(string searchText)
{
InitializeComponent();
_searchText = searchText; //have your text in ListPage now
}
I want to call a method of a Content from a master page sending a Parameter to manipulate one label.
public partial class MasterCategoria : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSalada_Click(object sender, ImageClickEventArgs e)
{
produtosCategoria x = new produtosCategoria();
x.changeLabel("Salada");
}
}
Manipulating this button on this WebForm which is a Content
public partial class produtosCategoria : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void changeLabel(string name)
{
lblTexto.Text = name;
}
But this isn't working. How can I do this work?
Thank you guys, and sorry about my english.
The object of type produtosCategoria is already created and it can be accessed from your master page via this.Page.
So to change the label of your content page you can do as in the snippet below.
Also, I added a simple type check so you won't get an error if another content page is loaded
protected void btnSalada_Click(object sender, ImageClickEventArgs e)
{
// Check if it is the correct content page
if (this.Page.GetType() == typeof(produtosCategoria))
{
produtosCategoria x = (produtosCategoria)this.Page;
x.changeLabel("Salada");
}
}
Note: When code executes in the master page this is the master page and this.Page is the content page
There are two pages in my app. First one is MainPage and second one is SettingsPage There is one textbox in my settings page. I want to save this textbox text and send to MainPage.
Here the new example. Now its working but I can't save the textBox1.text which is in the SettingsPage . It's cleaning when I navigate other page.
public sealed partial class MainPage : Page
{
private NavigationHelper navigationHelper;
public MainPage()
{
this.InitializeComponent();
progRing.IsActive = true;
Window.Current.SizeChanged += Current_SizeChanged;
this.NavigationCacheMode = NavigationCacheMode.Required;
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
}
public NavigationHelper NavigationHelper
{
get { return this.navigationHelper; }
}
private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
this.txtBoxNotification.Text = (string)e.NavigationParameter;
}
private void btnNotification_Click(object sender, RoutedEventArgs e)
{
webView.Navigate(new Uri("http://teknoseyir.com/u/" + txtBoxNotification ));
}
The standard way to send navigation parameters between pages in WP8 is to use
NavigationService.Navigate(new Uri("/MainPage.xaml?text=" + textBox1.Text, UriKind.Relative));
Then check for the parameter on the OnNavigatedTo() Method on the page you have navigated to.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string settingsText = NavigationContext.QueryString["text"];
}
For Windows Phone 8.1 you no longer navigate using a URI. The approach is to use:
this.Frame.Navigate(typeof(MainPage), textBox1.Text);
Then on the loadstate for the page you are navigating to you can get the data by using:
private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
string text = e.NavigationParameter as string;
}
Hope this helps.
You could also do this by using PhoneApplicationService. Set a value like this,
string str = textBox.Text;
PhoneApplicationService.Current.State["TextBoxValue"] = str;
Now you can call that value whereever you want using it key value. And get a value like this,
textblock.Text = PhoneApplicationService.Current.State["TextBoxValue"] as String;
In Windows Phone 8.1, you can transfer values as parameter of Frame.Navigate method.
For example, you want to transfer yourValue of yourType:
Frame.Navigate(typeof(TargetPage), yourValue);
and get it in target page:
protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
var value = navigationParameter as yourType;
}
the value is what you want to get.
The best easiest way I used for this is to declare a public static class in the main page so you can use the SAME class methods anywhere in your app pages as like this :
public static class MyClass
{
public static string MyString = null;
}
then you can give it a value from a text box from the settings page as like this :
PhoneApp.MainPage.MyClass.MyString = TextBoxInSettings.Text;
then give this value back to another text box in the main page as like this :
TextBoxInMainPage.Text = MyClass.MyString;
I want to pass one of the textbox's(on the master page) value into the user control(.ascx) page. Here is my code shows how to open user control..
Control usrCnt= LoadControl("userControl.ascx");
usrCnt.ID = "usrCnt";
ASPxPanel1.Visible = true;
ASPxPanel1.Controls.Clear();
ASPxPanel1.Controls.Add(userCnt);
How can post the textbox's value to the user control? I can't do like this..
Control usrCnt= LoadControl("userControl.ascx?param=" + textbox.Text);
Create a method for your usercontrol like SetText
and then
usrCnt.SetText("textValue");
if it is your webusercontrol code behind
public partial class WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void SetText(string theText)
{
this.Label1.Text = theText;
}
}
and if you've been added the control to the page
in page call it as
this.WebUserControl11.SetText(TextBox1.Text);
put these on the upper part of your usercontrol
private string _TextBoxValue = string.Empty;
public string TextBoxValue {
get { return _TextBoxValue; }
set { _TextBoxValue = value; }
}
then on your masterpage
usrCnt.TextBoxValue = TextBox1.Text;
For the quickest and dirty way is on your MasterPage
ViewState["TextBoxValue"] = TextBox1.Text();
and on UserControl, access ViewState["TextBoxValue"] to get the value.
I am a newbie to asp.net. I have an asp.net page which uses a user control.
On Page_Load event of this control, I want to change the title of the parent aspx page.
I need help on this please.
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = "New Title";
}
You can try create a property in usercontrol and next call this property using your instance of usercontrol in page like
In UserControl
protected void Page_Load(object sender, EventArgs e)
{
this.MyProperty = "This is a test";
}
public string MyProperty { get; set; }
`
In Page
protected void Page_Load(object sender, EventArgs e)
{
WebUserControl11.PreRender += new EventHandler(WebUserControl11_PreRender);
}
void WebUserControl11_PreRender(object sender, EventArgs e)
{
string str = WebUserControl11.MyProperty;
this.Header.Title = str;
}
Set this in your USERCONTROL:
this.Page.Master.Page.Header.Title = "text text title title";