Programmatically create table, enter values in it, retrieve the entire contents - html

When I go to parse through the table, all the stuff I created programmatically is missing...
I must be forgetting something so that it's losing all the stuff that I built programmatically (I am only getting the shell of the table).
Any ideas?
If I put the table in a Session object after I programmatically create it then it works except all the values the user enters will not be there obviously.
protected void btnSave_Click(object sender, EventArgs e)
{
SaveMainGrid(tblCC);
// SaveMainGrid((System.Web.UI.WebControls.Table)Session["tblMain"]);
}
private void SaveMainGrid(Control control)
{
foreach (Control ctrl in control.Controls)
{
if (ctrl is RadNumericTextBox)
{
RadNumericTextBox t = ctrl as RadNumericTextBox;
}
else
{
if (ctrl.Controls.Count > 0)
{
SaveMainGrid(ctrl);
}
}
}
}

This is likely another case of asp.net lifecycle. If you dynamically create controls, they aren't going to be available in the viewstate unless you recreate them. Even then, I don't know that the values would be persisted.
(I think they might. It's been a while since I fought this particular Web Forms quark.)
Check this question out for more info.
Why are you creating the table dynamically? Can you use an asp:GridView?

Related

Want to create an automation that switches between two tabs

I am new to automation and want to create an automation test which can do following:
Open one tab --- click and get some info from that tab
Switch to another tab --- click and get some info from this tab now.
Compare the infos.
We use Page Object Model to get info from one page. However the moment, I switch to another tab -- it switches the tab successfully but does not locate any element on it.
Any idea ?
Questions I would ask is,
Is the element locator correct?
Is this a unique element locator?
Is this a synchronization issue? Are you waiting enough for the page to load before finding the element?
Is this problem particular to a browser? Is it consistent across?
Also make sure you pass on the driver object from one page object to the other. Like,
public class PageOne {
public PageOne(WebDriver driver) {
//do something in constructor
}
public void someMethodInPage1() {
driver.findElement(By.id("button1")).click();
PageTwo pageTwo = new PageTwo(driver);
pageTwo.someMethodInPage2();
}
}
public class PageTwo {
private WebDriver driver;
public PageTwo(WebDriver driver) {
//do something in constructor
this.driver = driver;
}
public void someMethodInPage2() {
driver.findElement(By.id("button2")).click();
}
}

Keyboard overlaps popup in wp8

I am developing a Login screen in which the user needs to introduce their data and then submit them.
Considerations which I had: I have thought about using a Page, but eventually I rejected the idea because if I put Login page before the MainPage, then if I go back from MainPage, then it would go to Login page, which is not what I want. And if Login page were after MainPage, then if I execute for instance the app for first time, without being logged in, if I press back, then it would go to MainPage which I don't want as well.
The problem: I decided finally to use a Popup. At the moment looks perfect, but when I want to use a textbox, the Keyboard overlaps that textbox, and what I want is to move the Popup upwards just like a normal page. I don't know if is that possible, otherwise I am willing to hear some alternatives.
Thank you in advance.
In WMAppManifest.xml remove the property of Navigation Page and in you App.xaml.cs you have something like:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
LoadDefautPage();
}
void LoadDefautPage()
{
if (StartForFirstTime)//tombstone local variable
{
if (!IsLoggedIn)//flag save it in IsolatedStorageSettings
{
RootFrame.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
}
else
{
RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
StartForFirstTime = false;
}
}
finally remove Back Entry in MainPage:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
while (this.NavigationService.CanGoBack)
{
this.NavigationService.RemoveBackEntry();
}
}
It's just an idea, let me know how it goes (:

Password field color

I want to change the color of my JPasswordField with key Listener. I'm making a registration form and the user should fill the passwordfield at least with 8 characters that include digits and letters. Can anybody help me?
my code :
enter code here
public void keyPressed(KeyEvent e) {
if(e.getSource()==passwordField){
if(passwordField.toString().length()>=8)
passwordField.setBackground(Color.GREEN);
else
passwordField.setBackground(Color.RED);
}
}
When the keyPressed() event is fired the Document of the password field has not yet been updated, so the length will be 1 less than you think it should be.
Instead try using the keyTyped() method:
public void keyTyped(KeyEvent e)
{
JPasswordField password = (JPasswordField)e.getSource();
if(passwordField.getPassword().length >= 8)
passwordField.setBackground(Color.GREEN);
else
passwordField.setBackground(Color.RED);
}
Also, when writing a listener you should get the source of the event from the event object instead of trying to access an instance variable.
You may also want to consider using an InputVerifier on this field. The input verifier will prevent the user from tab away from this field unless at least 8 digits have been entered.
Note: even using the keyTyped() event you can still have problems because if the user uses the "BackSpace" key no event is generated. So maybe you should be using the keyRelased() event. Even this can cause a problem because if the users holds down a key multiple characters will be entered into the field before a keyReleased event is fired.
The best solution is to use a Document Listener. Read the section from the Swing tutorial on How to Write a Document Listener for more information.
you're doing it wrong
change to this
public void keyPressed(KeyEvent e) {
if(e.getSource()==passwordField){
if(passwordField.getPassword().length()>=8)
passwordField.setBackground(Color.GREEN);
else
passwordField.setBackground(Color.RED);
}
}
you should use getPassword()

NavigationService remove complete back navigation

Using NavigationService.RemoveBackEntry() I can remove one entry from the navigation stack. Is there a convenient way to remove all back navigation items in my app (scenario: I have a sign-up procedure which consists of multiple pages, and after successful registration I do not want the user to navigate back to the registration steps).
It's not that inconvenient to do that with RemoveBackEntry:
while(NavigationService.CanGoBack)
{
NavigationService.RemoveBackEntry();
}
Or use this, a single line code
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
while (NavigationService.RemoveBackEntry() != null) ;
}

how to display a video from a JList?

I am currently doing an application using Swing and i am stuck at a certain point. In my function, i have to link videos from a JList. The problem is i am not sure how to link the videos from the JList. I am using an OpenBrowser class to link the video to the internet. I did consider using JButton but i would have to hardcode it and that would be ugly. Is there any other alternatives to do this? I am in desperate need and would be eternally grateful to whoever that can help me.
Safa :)
If you don't want to open a browser with the video using a selection listener, you can consider the idea of launching it with a double click on a JList entry.
sample code
String[] items = {"i1", "i2", "i3", "i4"};
JList list = new JList(items);
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
JList list = (JList)evt.getSource();
if (evt.getClickCount() == 2) { //check if it is a Double-click
int index = list.locationToIndex(evt.getPoint());
// do whatever you want with the entry at that index
}
}
});
Desktp classes to browse some site (sample code):
if (desktop.isSupported(Desktop.Action.BROWSE)) {
URI uri = new URI("http://www.google.com");
desktop.browse(uri);
}
The desktop.browse() call will open your favourite browser with the given URL.