In my design there are three buttons. I want to open new windows on each button click. I have done upto open a new window. But when I click on the second button it opens in the same popup window. How can I avoid this and open three windows when click on these three buttons?
c# code
protected void btnApprove_Click(object sender, EventArgs e)
{
string ddlVal = ddlComp.SelectedValue.ToString();
if (ddlVal != "--Select The Competition--")
{
Session["ddlVal"] = ddlComp.SelectedValue.ToString();
ScriptManager.RegisterStartupScript(this, typeof(string), "APPROVE_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( 'approved.aspx', null, 'resizable=yes, status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);
}
else
{
WebMsgBox.Show("Select a competition");
}
}
This is the code I have used for all the three buttons with different page names
You can pass the name parameter as '_blank' instead of null.
Change the below line in your code
window.open( 'approved.aspx', null,
to
window.open( 'approved.aspx', '_blank',
If you're referring to top-level browser windows, you cannot - browsers disable this for obvious reasons (pop-up blockers, etc). You also cannot have more than one JavaScript alert() window open at a time.
Your WebMsgBox class wraps the alert() function. So this not possible.
You will need to change your client-code to instead display multiple elements (e.g. absolutely-positioned <div> boxes with a modal rectangular appearance).
Related
This code is used to generate radio button inside a window for each time the the "Add_list" button is clicked. The problem is whenever I close the windows or rebuild the program, every radio button that has been added by clicking the "Add_list" button disappear.
private void Add_list(object sender, MouseButtonEventArgs e)
{
// add radio button to the list
string filename = File_name.Text;
sp_list.Children.Add(new RadioButton
{
Margin = new Thickness(8, 0, 0, 0),
Content = filename
});
string [] array = { l_field.Text,width.Text,weight.Text, Concrete_tempreature.Text };
myAL.Add(array);
foreach (object obj in myAL)
{
Console.WriteLine(obj);
}
}
The question here is - why do you expect it work this way?
Nowhere in your code do you attempt to store the state of your window. WPF doesn't store window states - you need to implement this yourself.
I'm a newbie in c# and probably going to ask a very easy question, but I've not been able to find anything on the web to help.
I have a tabControl with a TabPage which is containing a TextBox object; this object, when the event "Text changed" is invoked, will perform the change of the parent tabPage's name.
The textbox where I typed "text changed by me" has a method which is managing changing the name of the tabPage:
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (this.textBox1.Text != "")
this.tabControl2.SelectedTab.Text = this.textBox1.Text;
else
this.tabControl2.SelectedTab.Text = "(no name)";
}
Into the current page menu is contained a control to add a new page, which runs this method when the user click on it:
private void addNewPageToolStripMenuItem_Click(object sender, EventArgs e)
{
int numPagine;
string strPagine;
numPagine = this.tabControl2.TabCount;
strPagine = numPagine.ToString();
this.tabControl2.TabPages.Add("new page" + strPagine);
}
...and here is the output, which is expected since I'm just asking to add a new empty tabPage:
So, my question is: how can I make possible that when the user is clicking on "Add new page", rather than creating an empty new tabPage the program is rather creating a page like the first one (i.e. containing a textbox into the same position which has a method to change the text of the parent tabPage that I have just created?
Here is an example.
//..
// create the new page
TabPage tpNew = new TabPage("new page..");
// add it to the tab
this.tabControl2.TabPages.Add(tpNew);
// create one labe with text and location like label1
Label lbl = new Label();
lbl.Text = label1.Text;
lbl.Location = label1.Location;
// create a new textbox..
TextBox tbx = new TextBox();
tbx.Location = textBox1.Location;
tpNew.Controls.Add(lbl);
tpNew.Controls.Add(tbx);
// add code to the new textbox via lambda code:
tbx.TextChanged += ( (sender2, evArgs) =>
{
if (tbx.Text != "")
this.tabControl2.SelectedTab.Text = tbx.Text;
else
this.tabControl2.SelectedTab.Text = "(no name)";
} );
For more complicated layout you may want to consider creating a user control..
You also may want to create the first page with this code; the, of course with real values for text and positions!
For creating a UserControl you go to the project tag and right click Add-UserControl-UserControl and name it, maybe myTagPageUC. Then you can do layout on it like on a form. A rather good example is right here on MSDN
The problem is that is has no connection to the form, meaning you'll have to code all sorts of references to make it work..
I'm not really sure if you may not be better off writing a complete clonePage method instead. It could work like the code above, but would loop over the Controls of the template page and check on the various types to add the right controls..
It really depends on what is more complicated: the Layout or the ties between the pages and the form and its other controls..
This is for iPhone.
I have a button and when it's clicked I want to pop-up another control which covers the whole screen. This screen could have any number of controls. And I can close this screen by clicking on an x in the top right corner or programmatically inside any event on the new screen.
I could probably do this by using a UINavigationController which just brings me to a new screen and has a link back to the previous screen but I would just like to ask if there is another option?
What I am doing is I have a map which shows a users location from a pin. But if the user wants to type in a new location instead of using the pin location then they will click a button, go to a new screen, type in an address and click a "suggested" address from what they type.
Any advice would be appreciated or a link to a code sample would be great
You can't use popover for iPhone, I think that you can use Modal View.
yourButton.TouchUpInside += (object sender, EventArgs e) =>
{
YourController yourController = new YourController();
yourController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
this.PresentViewController(yourController, true, null);
};
And to close you only need to dismiss the modal.
If it's an iPad app you can use UIPopoverController.
// myvc is an instance of the view controller you want to display in the popup
UIPopoverController pop = new UIPopoverController(myvc);
// target is another view that the popover will be "anchored" to
pop.PresentFromRect(target.Bounds, target, UIPopoverArrowDirection.Any, true);
If it's an iPhone app you can't use UIPopoverController. If you just want a small input box with a single button, you can use UIAlertView (this works for iPhone and iPad)
UIAlertView alert = new UIAlertView();
alert.Title = "Title";
alert.AddButton("OK");
alert.Message = "Please Enter a Value.";
alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
alert.Clicked += (object s, UIButtonEventArgs ev) => {
// handle click event here
// user input will be in alert.GetTextField(0).Text;
};
alert.Show();
I have several tab pages collection. By default when user open the apps, the first tab page is the start tab page, then user will close the tab page. Now I would like to create a situation where when the user go to the menu strip, click for example the "tab page 1 button", then the "tab page 1" will appear in the tab control. Any expertise can help me please...
Use the SelectedTab() method. It has three overloads.
If you have a reference to the tab:
tabControl1.SelectTab(tabPage2);
If you only know the index:
tabControl1.SelectTab(1); // 0-based index, this shows the second tab
If you only know the name:
tabControl1.SelectTab("tabPage2");
You say your users can click an [x] that removes the tab.
I'll assume it's removed by the easiest means, something like:
tabControl1.TabPages.Remove(tabPage1);
You can't focus on a tab that's not part of the tab control, so you'll have to add it back first.
tabControl1.TabPages.Add(tabPage1); // add tab as last tab in tabcontrol
tabControl1.TabPages.Insert(0, tabPage1); // or insert it at a specific index
tabControl1.SelectTab(tabPage1);
To select the tab page of the TabPage control, not only could user click the title to switch pages, but set the selectedTabPageIndex property (or like this) to do it.
Just have a try.
i am also facing this problem. Finally i solve by following code.
Scenario
My tab Control have many tabs and i make a [x] sign for closing that tab.
on click [x] my tab is remove from Tab Control.
Now when i click on button, i open the tab (that was Removed)
Code
private void openProductTab_Click(object sender, EventArgs e)
{
if (tabControlMdi.TabPages.Contains(tabProduct))//tab already present
{
tabControlMdi.SelectTab(tabProduct); // select by name
}
else
{
tabControlMdi.TabPages.Add(tabProduct); // add removed tab
tabControlMdi.SelectTab(tabProduct); // select by name
}
}
private void invoiceGenerationToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form form in Application.OpenForms)
{
if (form.GetType() == typeof(RETransactions.frmInvoicegeneration))
{
form.Activate();
foreach (TabPage item in tabControl1.TabPages)
{
if (item.Text == "Invoice Generation")
{
tabControl1.SelectTab(item);
}
}
return;
}
}
RETransactions.frmInvoicegeneration rTenancy = new RETransactions.frmInvoicegeneration();
rTenancy.Show();
rTenancy.TopLevel = false;
TabPage tabp = new TabPage("Invoice Generation");
tabp.Controls.Add(rTenancy);
tabControl1.TabPages.Add(tabp);
tabControl1.SelectTab(tabp);
tabp.BackColor = Color.Gainsboro;
}
// i hope it will work ... thank you
For my C# Windows Form Application, I have created a flowlayoutpanel that contains several panels. Inside the panel, I have a button "Clear" for each and every single panel.
How do I write the event handler for the code for the button "Clear" such that once I have click the button, the panel would sort of be "Removed" from the flowlayoutpanel.
This is a short part of the code of the adding of panels to the flowlayoutpanel.
nFlowPanel.Controls.Add(createNotificationPanel());
nFlowPanel.Controls.Add(createNotificationPanel());
nFlowPanel.Controls.Add(createNotificationPanel());
nFlowPanel.Controls.Add(createNotificationPanelImpt());
nFlowPanel.Controls.Add(createNotificationPanelImpt());
and this is the code for the button "Clear"
Button btnClear = new Button
{
Text = "Clear",
Name = "btnClear",
Location = new Point(416, 17)
};
p.Controls.Add(btnClear);
btnClear.Click += new EventHandler(buttonClear_Click);
So what should i write in the following method to have the effect of removing e.g. the second panel that was added in the first part of code I have written?
void buttonClear_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
EDIT
the code for creating my panel is
var p = new Panel
{
BorderStyle = BorderStyle.FixedSingle ,
Size = new Size(506,100),
Name = "notifyPanel"
};
and the code for creating my FlowLayoutPanel is
var nFlowPanel = new FlowLayoutPanel
{
FlowDirection = FlowDirection.TopDown,
WrapContents = false,
AutoScroll = true,
Size = new Size(530, 377),
Location = new Point(13, 145)
};
and the code for my button clear is
void buttonClear_Click(object sender, EventArgs e)
{
var button = (Control)sender;
var panel = button.Parent.Controls["notifyPanel"];
panel.Dispose();
}
however it gives the error
Object reference not set to an instance of an object.
on the panel.Dispose() line.
anyone can help?
The Controls.Remove() method is very dangerous, it doesn't dispose the control. Which will live on, moved to the so-called parking window, using up both Windows and managed resources. After a bit less than 10,000 times doing this it crashes your program when Windows is no longer willing to let you create any more windows.
Call the control's Dispose() method instead. That also automatically removes the control from its container.
void buttonClear_Click(object sender, EventArgs e)
{
var panel = nFlowPanel.Controls["notifyPanel"];
panel.Dispose();
}
You can do it like this:
nFlowPanel.Controls.Remove((sender as Button).Parent);
I will suggest you to use List for this. Before adding Panels in the FlowLayoutpanel, add them in the List. Then just remove the indexed panel from the flowlayoutpanel.
Panel pnlTemp = (panel)list[index];
nFlowPanel.Controls.Remove(pnlTemp);
To get the index of the button you have to add your buttons also to your list and after clicking any button, search the button in the list and get the index of the button where it is saved in the list. If my code is unclear, let me know. but I feel your task is that complex. I am not sure but this link may be of some help.
Hope it helps.