UWP - Validation on ContentDialog's PrimaryButtonClick? - vb.net

My ContentDialog is styled like a login form. It verifies password via connection thru SQLite. So in the Primary button's auto-generated Click event I have something like below (I made it Async btw):
Dim deferral As ContentDialogButtonClickDeferral = args.GetDeferral
If Await conn.Table(Of UserAccount).Where(Function(a) a.Username = UsernameTextBox.Text).CountAsync = 0 Then
args.Cancel = True
Dim x As New Windows.UI.Popups.MessageDialog("Username does not exist!")
Await x.ShowAsync
Else
'Other conditions
End If
deferral.Complete()
Some researching got me to think the Deferral is needed for Async situations (to no avail). Currently, with the above code I am getting a Reflection.TargetInvocationException on the Await line.
What I want to achieve is display a MessageDialog if username does not exist; the ContentDialog remaining onscreen for the user to correct himself.
Thanks!

Replace the "UsernameTextBox.Text" with a hardcoded value and it should work.
Maybe bind the textbox with a TwoWay mode into a variable and then use that variable in that statement.

Related

How to Disable Effect on Form Open/Close in vb.net?

I'm trying to make a program where there are multiple forms. Now what I would like to accomplish is that, whenever I open another form, the current form will close but I would like to do that without the forms having to vanish with an effect. Is there a way in the properties to do that? I tried changing the DoublBuffered into TRUE but it has no effect (I mean, the effect was still there). Can somebody point me to the right direction please? Thanks in advance. :D
By the way, I'm using:
Form2.Show()
Me.Close()
I haven't tried it out, but you can use the following. Assuming you have 2 Forms(1,2)
private void Form1_Load(Object sender, EventLog e)
{
if((bool)Form1.ActiveForm)
{
Form1.Visible = true;
Form2.Visible = false;
// Rest of your code to display
}
if((bool)Form2.ActiveForm)
{
Form1.Visible = false;
Form2.Visible = true;
// Rest of your code to display
}
}
Use this,
Form1.Opacity = 0
Here are places to add it. First set Form 2 opacity as 0 in visual studio. and then go to the form load and after loading all the things you need put in,
Form2.Opacity = 100
Then before form 1 closing put in,
Me.Opacity = 0
You just need to know where to set to 0 and where to 100. It will work good. But I am not sure why you don't want that effect.

Windows Store App Search Contract Blank Screen

I recently added the search contract to my app. It is working great! But, whenever I search in the app when it is not running, it only starts with a blank screen. I did the part to add search results even in OnSearchActivated method. But even if I remove the code that I added, the blank screen persists. I created a blank project and added the search contract to it. And it is working in it even when the app is not running. The issue seems to be with my app only. I cannot debug it because it is something that runs when the app is not even running. Tell me a solution.
Code in OnSearchActivated and OnLaunched
Protected Overrides Async Sub OnSearchActivated(args As Windows.ApplicationModel.Activation.SearchActivatedEventArgs)
Dim previousContent As UIElement = Window.Current.Content
Dim frame As Frame = TryCast(previousContent, Frame)
If frame Is Nothing Then
frame = New Frame
Common.SuspensionManager.RegisterFrame(frame, "AppFrame")
If args.PreviousExecutionState = ApplicationExecutionState.Terminated Then
Try
Await Common.SuspensionManager.RestoreAsync()
Catch ex As Common.SuspensionManagerException
End Try
End If
End If
frame.Navigate(GetType(SearchResultsPage1), args.QueryText)
Window.Current.Content = frame
Window.Current.Activate()
End Sub
Protected Overrides Async Sub OnLaunched(args As Windows.ApplicationModel.Activation.LaunchActivatedEventArgs)
AddHandler SearchPane.GetForCurrentView.SuggestionsRequested, AddressOf OnSearchPaneSuggestionsRequested
'Contains definition of arrays ExNam, ExAbbr, ExInst, etc. removed from here to shorten the code and focus on its logic
If rootFrame Is Nothing Then
rootFrame = New Frame()
Train_Thy_Brain.Common.SuspensionManager.RegisterFrame(rootFrame, "appFrame")
If args.PreviousExecutionState = ApplicationExecutionState.Terminated Then
Await Train_Thy_Brain.Common.SuspensionManager.RestoreAsync()
End If
Window.Current.Content = rootFrame
End If
If rootFrame.Content Is Nothing Then
If Not rootFrame.Navigate(GetType(Instructions), args.Arguments) Then
Throw New Exception("Failed to create initial page")
End If
End If
Window.Current.Activate()
End Sub
'Also the namespace definitions are done at the top so they are not the issues neither.
There is a solution to debug your app : in VS2012, Right-click on your project in the Solution Explorer, then go to the Debug tab and in the Start Action section, check "Do not launch, but debug my code when it starts".
Now you can start your app from the Search Contract even if it is not running yet and debug it!
Now for your problem, I would suggest you to check whether the data is loaded before you actually search for something.
You might be hitting the search activation with empty query string. Check your search activation handler, whether you are handling the blank query text case or not?
protected override void OnSearchActivated(SearchActivatedEventArgs args)
{
// your app initialization code here.
Frame frame = (Frame)Window.Current.Content;
if (!string.IsNullOrEmpty(args.QueryText))
{
frame.Navigate(typeof(SearchResultsPage), args.QueryText);
}
else
{
// navigate to your app home page if the query text is empty.
frame.Navigate(typeof(Home), null);
}
Window.Current.Activate();
}

Clearing input textbox using FuncUnit

I am writing FuncUnit for my application. I am browsing the application in Google Chrome. I have a textbox which is initially hidden. I need to make it visible and then clear the text already present in that textbox. I have the following code which makes the box visible but fails to clear the text in it.
S('#search').visible().clearText();
Can anyone tell what is wrong here?
Try to clear the textbox by typing - Ctrl+A and Delete.
var input = S('input.my-input');
input.type('[ctrl]a[ctrl-up][delete]', function() {
// Continue in test case after the text has been removed
});
Your statement is not accurate. visible() does not turn things visible. It is a wait function which waits for the source element to become visible before proceeding to the next action.
koalix's key sequence works. With the type() command you might need to first click into the text input before clearing it.
Try:
S('#search').visible().click().type('[ctrl]a[ctrl-up][delete]');
You could also try empty quotes <" ">
var input = S('input.my-input');
input.type('', function() {
// remove existing text
});
I don't know if you're still waiting for an answer.
I think you're not using visible() in the correct way.
In FuncUnit (see docs here), among other things, you can distinguish between "actions" and "waits". visible() is a wait, and should be used to wait for an element to become visible, like this:
S('#el').visible( function() {
// do something when element with id="el" becomes visible
});

Get a Monotouch.Dialog InputElement for a password field

I am trying to get the value from an EntryElement
var password = new EntryElement("Password","Password",null,true);
I have a StyledStringElement with a click event like
new Section()
{
new StyledStringElement ("Login", delegate {
Console.Write (string.Format("Password is {0}",password.Value));
Console.Write (string.Format("Email is {0}",email.Value));
})
When I click on the element I can see the email string value however the password is always null.
What do I need to do differently to get the password value?
make sure you have pressed return on the iPhone keyboard, if not the value will not saved

Dojo OnKeyPress Handler: TextBox value is blank

I have a Dojo form that does not contain a submit button. Instead, I added an onkeypress handler to calls a method when Enter is pressed. The problem I am having is that when I hit enter before blurring off the current field, the _process method thinks that field is empty.
Or in other words: type in field1. hit tab. type in field2. hit enter. field2 is blank unless i click off the field or shift-tab back.
Any ideas?
dojo.connect(dijit.byId("fkrform"),"onKeyPress",function(e) {
if (e.keyCode == dojo.keys.ENTER) {
_process();
}
and the method it calls:
function _process()
{
var field1 = dijit.byId("field1").value;
var field2 = dijit.byId("field2").value;
alert(username);
alert(password);
...do stuff...
}
The fields are of dojoType: dijit.form.TextBox, and the form is: dijit.form.Form
Use dijit.byId('field1').get('value') instead of directly try to access the property "value". In your example you saved the value in the variable field1 and field2 and in the alert you use the variable username and password could be the answer why you don't get anything. But you still should use the get method to get a property instead of directly access the property.
When you press "Enter" your form will submit. So you need to connect to the "onSubmit" event on the form, instead of onkeyPress or onKeyUp.
The first example i created prints the value of the input box on every key someone pressed in the console.
http://jsfiddle.net/a8FHg/
But what you really wanted was hooking into the submit. I modified the example. The new example connects to "onSubmit" and creates an alert box with the text of the user input.
http://jsfiddle.net/a8FHg/1/
For completness if jsfiddle doesn't work some day. You JavaScript should looks like this.
dojo.ready(function(){
var form = dijit.byId('form');
var box = dijit.byId('box');
var submit = function(event) {
dojo.stopEvent(event);
alert("User input was " + box.get('value'));
};
dojo.connect(form, 'onSubmit', submit);
});
Assuming your form in your HTML has the id form and your box have the id box.