AutoCompleteExtender - PageMethod has no data to return - c#

I am making use of the AutoCompleteExtender and need know how to handle the scenario when the PageMethod has no data to return. I am currently making use of 'OnClientPopulating' and 'OnClientPopulated'
In the 'OnclientPopulating' I am doing the following:
function suggestionListPopulating(source, e) {
var textboxControl = $(source.get_element());
textboxControl.css('background', '#FFF url(images/loading3.gif)no-repeat right');
}
In the 'OnclientPopulated' I am doing the following:
function suggestionListPopulated(source, e) {
var textboxControl = $(source.get_element());
textboxControl.css('background-image', 'none');
}
Of course, since no data is being returned in certain; which is fine and correct, the 'OnClientPopulated' event is never firing, thus leaving a background image in my textbox.
Is there a way to clear the texbox background if the textbox control is not populated? Meaning a list never pop-ups to select from.

I found a descent workaround if anyone is interested.
http://www.aspforums.net/Threads/120948/ASPNet-AJAX-AutoCompleteExtender-Display-No-records-found-message-when-no-matches-found/

Related

GridView doesn't scroll down to virtualized items

In my application, I need to select the newly created document(note) when I go back to library. After library item is selected, the Library must be scrolled to the selected item.
My library's OnLoaded method:
private async void OnLoaded(object sender, RoutedEventArgs e)
{
await this.ViewModel.InitializeAsync();
// CollectionViewSource of my GridView being filled
ViewModel.CollectionChanging = true;
GroupInfoCVS.Source = ViewModel.GroupsCollection;
ViewModel.CollectionChanging = false;
// Loading Last selected item - THIS CHANGES SELECTION
ViewModel.LoadLastSelection();
}
After I call the LoadLastSelection method, selection is changed successfuly (I've tested). This is the method that is called after that (in our GridView's extended control):
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
this.SelectedItemsCount = this.SelectedItems.Count;
var newlySelectedItems = e.AddedItems;
if (newlySelectedItems.Any())
{
var item = newlySelectedItems.Last();
ScrollTo(item);
}
}
private void ScrollTo(object item)
{
UpdateLayout();
var itemUI = (FrameworkElement)this.ContainerFromItem(item);
if (itemUI != null)
{
_scrollViewer.UpdateLayout();
_scrollViewer.ChangeView(null, itemUI.ActualOffset.Y - itemUI.ActualHeight, null, false);
}
}
This also works for the most part. When itemUI is not null, the method scrolls successfully to the required item. The problems start when the items start to overflow the screen size. When items are completely hidden from the screen, they are virtualized. That means that ContainerFromItem returns null, so I can't take the offset properties. Keep in mind that this actually occurs before Library's OnLoaded method is finished.
Please, help me with some alternative to get such properties or other methods of scrolling, which will help me scroll successfully.
I've read a lot and tried using Dispatcher.RunAsync and ScrollIntoView methods, but I couldn't manage to produce any scrolling behavior. If you point me how to use them successfully, that would be a nice help too.
Here's what I've read (and tried):
ItemContainerGenerator.ContainerFromItem() returns null?
How to Know When a FrameworkElement Has Been Totally Rendered?
Is there a "All Children loaded" event in WPF
Let ListView scroll to selected item
Thanks in advance!
IMPORTANT: If you don't want to read all the conversation within the official answer, please read the solution in short here:
TemplatedControl's style had changed ScrollViewer's name from "ScrollViewer" to "LibraryScrollViewer" and that rendered ScrollIntoView method useless.
For GridView, the best way to achieve your needs is to call GridView.ScrollIntoView.
But you seem to have made similar attempts, and it does not to be successful, then the following points may help you:
1. Don't use GridView as a child element of ScrollViewer.
In your code, I see that you are calling the method of ScrollViewer.ChangeView to adjust the view scrolling, so it is speculated that you may put the GridView in the ScrollViewer, which is not recommended.
Because there is a ScrollViewer inside the GridView, and its ScrollIntoView method is to change the scroll area of the internal ScrollViewer. When there is a ScrollViewer outside, the ScrollViewer inside the GridView will lose the scrolling ability, thus making the ScrollIntoView method invalid.
2. Implement the Equals method of the data class.
If your data class is not a simple type (such as String, Int32, etc.), then implementing the Equals method of the data class will help the GridView to find the corresponding item.
Thanks.

C#: How to make a AutoComplete textbox using Google API in WinForms

I'm actually trying to make something like this but in WinForms: https://google-developers.appspot.com/maps/documentation/javascript/examples/full/places-autocomplete-addressform?hl=es
When you write some address, the TextBox expand and show you suggestions, and it updates every time you change the content of TextBox.
I write a method like GetAddressPredictionsByInput(string input) using Google API, but I dont know when I should call it, and how can I update suggestions like in the example, because if I change the AutoCompleteCustomSource everytime the TextChanged method is called, the control lost focus, and also too many calls to WebService freeze the program a little.
Hope you understand and help me.
Sorry for bad english.
EDIT:
Okey, I thought it wasn't necessary, this code is really simple and I explained it with words, but you down voted my question. This is my code:
private void textBoxEx1_TypingCompleted(object sender, System.EventArgs e)
{
var autoCompleteListCollection = new AutoCompleteStringCollection();
autoCompleteListCollection.AddRange(new GoogleApi.Instance.GetAddressPredictionsByInput(textBoxEx1.Text).ToArray());
textBoxEx1.AutoCompleteCustomSource = autoCompleteListCollection;
}
Update: I partially answered my own question with:
I make a CustomControl that inherits TextBox and add a CustomEvent that is called when you stop typing for 2 seconds. Then, I call the method that returns an Array of Address (string) and I want to show it as suggestions.

Assigning JS in code behind for textbox to receive focus

In my code I'am inserting new record to database then reloading listand only thing i would like to do now is to set focus to TextBox that represents new record. In code behind after reloading list I'am able to obtain reference to that TextBox. So basically I need to register script that after load will fire and set focus to that control, but I'm not sure how to do that, can you help guys ? :)
{
TextBox txt = (TextBox)lastRow.Cells[1].Controls[0];
//Here I need to assign script
}
I'm not 100% sure I understand your question, but if I do, this Javascript should do the job:
document.getElementById("myTextbox").focus();
I assume you are using asp.net pages
on page constructor you can subscribe to Loaded event and then call the textbox.Focus()
public MyPageName()
{
this.Loaded += myloadedEventHandler;
}
void myloadedEventHandler(object sender,EventArgs args)
{
textBox.Focus();
}

ScintillaNET Autocomplete and CallTip

I am using ScintillaNET to make a basic IntelliSense editor. However, I have a problem when I call _editor.CallTip.Show("random text") in the AutoCompleteAccepted Event.
If I type pr for example, and scroll and select printf in the drop-down list, it goes to my AutoCompleteAccepted event and when I call the CallTip.Show, the rest of the word does not get added (however, without that CallTip code, the rest of the word is filled).
So, if I typed pr then it stays pr and I get my CallTip. How do I make sure the rest of the word gets inserted AND the CallTip shows?
Is the AutoCompleteAccepted Event not the right place to call it? If so, where should I call the CallTip.Show so that it works side-by-side with my AutoComplete?
Finally figured it out! The AutoCompleteAccepted Event isn't the right place to put CallTip.Show
What is going on is the fact that when AutoCompleteAccepted Event is called and you add text to the ScintillaNET control, it takes time for the UI to update and so, when you call to show the CallTip, it interferes with the text being inserted into the control.
The better way to do it is to call CallTip.Show in the TextChanged event, as they you know that the text has been inserted when the AutoCompleteAccepted Event was called.
It would now look something like this:
String calltipText = null; //start out with null calltip
...
private void Editor_TextChanged(object sender, EventArgs e)
{
if (calltipText != null)
{
CallTip.Show(calltipText); //note, you may want to assign a position
calltipText = null; //reset string
}
...
}
...
private void Editor_AutoCompleteAccepted(object sender, AutoCompleteAcceptedEventArgs e)
{
if (e.Text == "someThing")
{
/* Code to add text to control */
...
calltipText = "someKindOFText"; //assign value to calltipText
}
}
That is essentially what can be done to ensure the AutoComplete fills correctly and you get the CallTip to show.
Just note, that the CallTip MAY end up in unintended places, so it is recommended to set the value of where you want the CallTip to show up

Button Questions in MonoTouch

I'm working with MonoTouch and I have come up with three questions around buttons that I'm hoping someone can help me with.
I'm trying to change the "Back" button in the title bar. How do I do this? I've seen the thread posted here: How to change text on a back button. However, that doesn't work. I get the vibe that I'm not accessing the controller property. Currently, I receive a NullReferenceException when I attempt to set the button text in the ViewDidLoad method. Currently, I'm trying to set the text like such:
this.NavigationItem.BackBarButtonItem.Title = "Back";
I have the suspicion that I'm not accessing the root controller, but I'm not sure how to do this.
For a "back" button on a separate page, I want to perform a custom action. I want it to go back like it does. But before that happens, I want to execute some custom code. How do I do this?
I need to create something that looks like a hyperlink within a paragraph of text. How do I do that?
MonoTouch seems cool. However, the learning curve is a bit steeper than I had anticipated. Thank you!
For your first question the MonoTouch-specific answer (to the question you provided) works perfectly.
this.NavigationItem.BackBarButtonItem = new UIBarButtonItem ("MyBack", UIBarButtonItemStyle.Plain, null);
Make sure to the all the answers. This code needs to be called in the pushing controller, not the controller being pushed.
UPDATE
For your second question you likely noticed a few overloads that takes a Selector or a delegate. However they won't work for a Back button.
One way to work around this iOS limitation is to override ViewDidAppear or ViewDidDisappear to get similar notification.
I solved your third question by creating a custom button in de viewbuilder. Setting the type to custom removes de standard borders and makes it look like a line of text. Simply change its size and style it to make it look more like an hyperlink. I left an empty space in my text and and put my custom button in that space.
I created an extension method that allows you to change the back button text and optionally handle the TouchUp action with your own code. It also keeps the same border look as the default back button.
public static class MyExtensions
{
public static void SetCustomBackButton(this UIViewController uiViewController, string buttonText, Action onClick)
{
uiViewController.NavigationItem.HidesBackButton = true;
var dummyButton = UIButton.FromType (UIButtonType.Custom);
var backButton = (UIButton)MonoTouch.ObjCRuntime.Runtime.GetNSObject (
MonoTouch.ObjCRuntime.Messaging.IntPtr_objc_msgSend_int (
dummyButton.ClassHandle, MonoTouch.ObjCRuntime.Selector.GetHandle ("buttonWithType:"), 101));
backButton.SetTitle (buttonText, UIControlState.Normal);
backButton.TouchUpInside += delegate {
if (onClick != null)
onClick ();
else
uiViewController.NavigationController.PopViewControllerAnimated (true);
};
uiViewController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem (backButton);
}
}

Categories