I've been racking my brain over this for a while, its been a while since I had to do this and know its possible I've done it in another project in the past that I don't have a backup of to refer to.
I have a Login View on a page inside the login view is 2 panels one panel with a login control (to login) and one panel with a createuserwizard (to register) and a second button to click to register.
I'm trying to hide the panel with the login control and show the panel with the register control via a button click but all I end up with is a null reference exception.
this is what I have currently.
protected void Register_Click(object sender, EventArgs e)
{
FindControl("LoginView1").FindControl("LoginPanel").Visible = false;
FindControl("LoginView1").FindControl("RegPanel").Visible = true;
}
I appreciate any help thanks.
I figured out what the problem was so I'll leave the question here for anyone who may have the same problem and stumble across this
I was so used to working with controls from a master page but within a page that's inside the master page you don't need the first findcontrol its simply:
protected void Register_Click(object sender, EventArgs e)
{
LoginView1.FindControl("LoginPanel").Visible = false;
LoginView1.FindControl("RegPanel").Visible = true;
}
Related
I have a button inside a form which is itself inside a panel and that panel is also inside a panel. I want to set focus to that button as soon as the page loads. I have tried many different methods to achieve focus but unable to do so. Can anyone please guide me?
private void directionform_Load(object sender, EventArgs e)
{
this.ActiveControl = button1;
button1.Focus();
button1.Select();
}
I have a masterpage, contentplaceholder and an .ascx page.
The user enters his username-password at Masterpage.
I want to prevent the load of the contentplaceholder, if the user enters wrong username&password combination. Currently I am just disabling it's visibility, which does the trick but the page is still loaded, goes to database etc. which is useless since all of them will not be shown anyway.
You can load the Controls dynamically.
private WebUserControl1 userControl;
protected void Button1_Click(object sender, EventArgs e)
{
if (loginOK == true)
{
buildControls();
}
}
private void buildControls()
{
userControl = (WebUserControl1)LoadControl("~/WebUserControl1.ascx");
PlaceHolder1.Controls.Add(userControl);
}
Dynamically added controls need to be recreated on every Page_load
(that includes PostBack). So always call buildControls() when a user
is logged in.
May I know if there is any way to invoke a method from the child page(.aspx) after the page load of the user control is finished?
Right now I have an issue of being unable to retrieve the value from the child page because the variables from the user control has not been assigned the value yet.
To put it simply
FROM MY .ASPX FILE
Page_Load(object sender, EventArgs e)
{
x = getValueFromUserControl();
}
FROM MY USER CONTROL
Page_Load(object sender, EventArgs e)
{
int x = getvalueFromDatabase();
}
getValueFromuserControl()
{
return x;
}
Since the ASP.NET Life Cycle goes from the child page(.aspx) page_load -> user control page_load, I am unable to retrieve the value of x.
That said, ideally I would not like to put the function in the child page and call it from the user control as the user control is being used in other pages.
In short, I would like to invoke a method from my .aspx page after the page_load in my user control ends, Thank you!
Get the value at a later page event:
protected override void OnLoadComplete(EventArgs e) {
x = getValueFromUserControl();
}
Unless, of course, there is a specific reason why you must get the value on Page_Load. There are other, probably more appropriate ways to handle this, but without knowing what x is and what you need to do with it, it is hard to give any other advice. For example, maybe the UserControl should fire an event that is handled by the page.
I'm trying to make a card game using Windows Application Forms.
The thing is that I don't know how to do the following- for example if i'd have 3 buttons- one of them named, for example, "Play", if i'd click on it, it would open the actual game, but in the same window, it would only make the buttons dissapear, and when i'd click back, it would open the window with buttons again. I don't really know how to explain my problem better, hopefully someone can tell me how to do that.
You don't have to hide / show the buttons. What you can do instead is to make a new form with the cards on it. That Form will pop up after you click the play button.
private void PlayButton_Click(object sender, EventArgs e)
{
// You other functionality goes here
GameForm GF = new GameForm();
GF.Show();
//Or - try this and see the difference
GF.ShowDialog();
}
Good Luck!
In addition to Leez's answer, in your situation, you should think about using container controls rather than handling the visible states of individual controls.
You could put related controls in a Panel, GroupBox or TabControl and set the visible properties of those containers instead.
you can use Visible property of button to do that as follows.
private void button1_Click(object sender, EventArgs e)
{
// You other functionality goes here
button1.Visible = false;
}
I've a devexpress Navigation menu item that opens a data entry form (user control). The user control has validation rules that compel users not to leave textboxs blank. And, it works pretty good so far.
But, the problem comes when I click on other menu items while the data entry user control is already displayed. This time, the screen just freezes and stucks, and I've to restart the system. What are the possible causes and solutions? Thanks in advance
Here are some code snapshots:
//Here is what I've on the main form. It has a panel control called mainPanel to display the user controls
private XtraUserControl uc;
private void MainForm_Load(object sender, EventArgs e)
{
displayUserControl("Data Entry");
//...
}
private void navigationBar_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
{
displayUserControl(e.Link.Caption);
}
private void displayUserControl(string link)
{
switch (link)
{
case "Data Entry":
uc = new ucDataEntry(); //the data entry user control that freezes the system
break;
case "Setting":
uc = new ucSetting();
break;
case "Chart":
uc = new UCReportChart();
break;
}
mainPanel.Controls.Clear();
mainPanel.Controls.Add(uc);
uc.Dock = DockStyle.Fill;
uc.Show();
}
Any time a menu item is clicked, you are clearing the previous control out of your main panel, and replacing it with a new one. Perhaps it is the validation logic in the ucDataEntry control that is causing the application to hang? (You haven't posted code for that control, so I can't be sure.)
As an aside, by calling mainPanel.Controls.Clear(), you are leaking memory. The documentation for this function states that you must explicitly call the Dispose() method for any controls that are cleared in this manner.