I am working at a problem in ASP.NET.
I have to create 2 windows (i think that I need to make web forms, i don't know why they said windows) one is the login form, when i press ok and the username and password is ok, I need to
show my second window (webform)
How can I do that?
I tried to do
protected void Button1_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.SetFocus("id");
}
But it gives me error
A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.
What should I do?
Am i right, I have to do separate webforms for thoose windows?
This is the picture from the problem that they provided
If you use webforms you can just use the following code to redirect to second form:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Webform2.aspx");
}
Related
I have a C# Windows Forms App that contain a menu bar.
I want to display a Help Message when I press on the "HELP" menu button.
All that I can see when I press view code is this:
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
}
I think that I need to create inside the function a MessageBox or an event that will display the desired message.
Do you have any idea how should I do this, please?
Below should work for what your asking. If you are on your form you can double click the button you want to interact with, and Visual Studio should take you to the empty method.
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("This is supposed to be helpful");
}
I am designing a web form for registration purpose with the drag and drop interface. When I add validation control like RegularExpressionValidator and required RequiredFieldValidator it shows this above titled message when I run it.
Turns out i found the solution.
You just need to write this in your C# code
protected void Page_Load(object sender, EventArgs e)
{
this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
}
for beginners just double click the components of your page while you are not in debugging mode double clicking a text field will direct you to the C# page.
Working on a windows 8 store app, so I've managed to pass a parameter to another page, but how do I call it on the other page?
private void Button1_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(Test), Testbutton);
}
As you can see Testbutton is what I am passing, so on another page I want to call it, then on a button click I will disable the button. The disable button part I know how to do.
I have a Login form that users use to log in. After logging in, they will be presented with another form, and this form contains different labels. Each label is being treated as a button. The form is divided into 2 panels, the left panel is for the labels, and the right panel is for the button action. For example, I have 3 labels on the left side one called "Home" and the other one is "Register User" and lastly "Log Out" when I press the label "Users" a TabControl will be showing on the right side and it has 2 tabs "Register user" And "Current Users".
After I click on "Log Out" and I log in with a different user I want everything to be clean just like if I was opening it from the beginning. For example, the Home page should show first and not the last visible panel. If I log in with user called "test" now and I click on "Users" and then log out and log in from a different user I will still see The "Users" panel open and every value entered in textboxes is still open. And I don't want this.
The code I used to log out is:
private void LogOutBtn_Click(object sender, EventArgs e)
{
this.Close();
Globals.LoginForm.Show();
}
The code I use to move from the login form to the welcome form is:
private void LoginBtn_Click(object sender, EventArgs e)
{
this.Hide();
Globals.WelcomeForm.ShowDialog();
}
Try declaring a new WelcomeForm each you show it. Something like this:
private void LoginBtn_Click(object sender, EventArgs e)
{
Globals.WelcomeForm NewWelcomeForm = new Globals.WelcomeForm();
this.Hide();
NewWelcomeForm.ShowDialog();
}
The new constructor will reset all the controls and their values.
Never Mind I got it working. I know my mistake :) declaring it in a different class and calling from that class was causing me this problem.
My code now is
private void LoginBtn_Click(object sender, EventArgs e)
{
Welcome NewWelcomeForm = new Welcome();
his.Hide();
NewWelcomeForm.ShowDialog();
}
I created a UserControl with the buttons Save, Close and Cancel. I want to close the form without saving on the Cancel button, prompt a message to save on the Close button and Save without closing on the Save button. Normally, I would have used this.Close() on the Cancel button, but the UserControl doesn't have such an option. So I guess I have to set a property for that.
Scrolling down the "Questions that may already have your answer" section, I came across this question: How to close a ChildWindow from an UserControl button loaded inside it? I used the following C# code:
private void btnCancel_Click(object sender, EventArgs e)
{
ProjectInfo infoScreen = (ProjectInfo)this.Parent;
infoScreen.Close();
}
This does the job for one screen, but I wonder if I have to apply this code for all the screen I have? I think there should be a more efficient way. So my question is: Do I need to apply this code for every form I have, or is there another (more efficient) way?
you can use
((Form)this.TopLevelControl).Close();
you can use the FindForm method available for any control:
private void btnCancel_Click(object sender, EventArgs e)
{
Form tmp = this.FindForm();
tmp.Close();
tmp.Dispose();
}
Do not forget to Dispose the form to release resources.
Hope this helps.
You also can close one form in any part of the code using a remote thread:
MyNamespace.MyForm FormThread = (MyNamespace.MyForm)Application.OpenForms["MyForm"];
FormThread.Close();
I found the simple answer :) I all ready thought of something like that.
To close a WinForm in a ButtonClicked Event inside a UserControl use the following code:
private void btnCancel_Click(object sender, EventArgs e)
{
Form someForm = (Form)this.Parent;
someForm.Close();
}