Showing posts with label behavior. Show all posts
Showing posts with label behavior. Show all posts

Wednesday, March 28, 2012

Extend AutoCompleteExtender behavior

I have written the webservcie to parse the prefixText on semicolom ";" (if present) and return completion list based on the character after the semicolon. That works great, however on the client when a value from the completion list is selected, it overwrites the text box contents.

So for first case I type a charcter 'a' and select ASP from the list, then I add ASP;c to the text box and get a completion list with values {"C#","Code"}. On selecting C# it overwrites the contents in the text box, I want it to be ASP;C#

I want to extend this behavior to append the selection from completion list to the contents of the text box in order to implement gmail type functionality.

Has anyoneout there tried to implement the sutocomplete extender this way.

Thanks in advance.

This is an interesting idea that I had not thought about. It should be possible already using my custom auto complete extender (see signature). I raise an event when an item is selected letting you pass back the string that you want in the textbox. I do this because I use objects instead of just strings returned from my website, so I need to be able to pick the text I want to place in the textbox. So, you could handle this event and append the values and pass the entire value back.


Thank you for a prompt reply.

Its possible to send back the whole string to the completion list. So for first search "a" will yield ASP. Adding ASP;c to the text box will have to get {"ASP;C#","ASP;Code"}

This approach might not help if the text is long (like email address) and won't look as if it is enhancing the user experience either. Is there any other way to achieve this.

Thanks Again


Any other ideas how to achieve this.

Is there a way to add this to the enhancement list with the Atlas team?

Any help is appreciated.

Thanks Again.

Saturday, March 24, 2012

Exception Handling?

It looks like there's no handling for server side errors at this point at least for the Web Service behavior. If I do the following:

[WebMethod]

publicbusCustomer GetCustomer()

{

thrownewSoapException("Failure dude!",SoapException.ServerFaultCode);

returnnewbusCustomer();

}
The call simply doesn't complete to any of the callbacks. Is there anyway to get any error info out of this? It seems to me that the result values should either include some sort of complex object that contain a reference to an error object or else provide some sort of other mechanism that notifies you of an error. Instead of a Timeout method, maybe there should be a more general Error method with an error object you can query for what type of error occurred on the server.

Hello

Try this on the client side javascript:

function displayTimeout(result)

{

alert('timeout:\n' + result);

}

function dispalyError(result)

{

alert('error:\n' + result);

}

function callMyWebservice()

{

GetCustomer(CallbackMethod,displayTimeout,displayError);

}

You can also use Fiddler to view the data returned from the Webservice. (www.fiddlertool.com)


Hi,

following the suggestion given by donaldduck1312, you have to declare an error callback for the asynchronous request. When the callback is invoked, you receive a Web.Net.MethodRequestError instance as the first parameter; this object has methods that allow to display infos about the error:

function onError(e) {
alert('Server Error: ' +
e.get_exceptionType() + '\r\n' +
'Message: ' +
e.get_message() + '\r\n' +
'Stack Trace: ' +
e.get_stackTrace());
}

Wednesday, March 21, 2012

Event handler gets removed after AJAX refresh.

Hi,

I add an event handler on window.onload.
However, this seems to get removed after AJAX refresh.

Following are steps to reproduce behavior.
What may I have missed.

Thanks.
yagimay

[steps]

1. Create an ASP.NET AJAX-Enabled Web Site.
2. Add ScriptManager, UpdatePanel and a TextBox (inside the panel) on web form.
3. Add following script block to web form.

<script type="text/javascript">
window.onload=init;
function init(){
var tx=$get("TextBox1");
$addHandler(tx,"click",txt_click);
}
function txt_click(e){
var tx=e.target;
alert(tx.id+": input numbers.");
}
</script>

4. Add following server side code.

Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

Dim str As String = TextBox1.Text
If Not IsNumeric(str) Then
str = "N/A"
Else
Dim val As Double = Double.Parse(TextBox1.Text)
str = val.ToString("c")
End If
TextBox1.Text = str

End Sub

5. Debug.
6. Click TextBox.
-- TextBox.onclick event occurs (alert appears).
7. Input anything and press [Enter] key.
-- UpdatePanel refresh and TextBox.Text is updated.
8. Click TextBox.
-- TextBox.onclick event does not occurs anymore.

I was able to get this work by using PageRequestManager.add_pageLoaded instead of window.onload.

<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(init);

function init(sender,args){
var tx=$get("TextBox1");
$addHandler(tx,"click",txt_click);
}
function txt_click(e){
var tx=e.target;
alert(tx.id+": input numbers.");
}
</script>

Thanks.

yagimay