Login  
Search All Forums
Dart Home | PowerWEB TextBox for ASP.NET | Custom Development Reply | PowerWEB TextBox for ASP.NET Topics | Forums   
AuthorForum: PowerWEB TextBox for ASP.NET
Topic: Detecting custom OnChange event
RyanH

From: Ottawa, ON Canada
Posts: 29
Member Since: 06/27/06
posted June 27, 2006 4:30 PM

I've seen some similar posts on this, but I am still a little unsure what to do in my case. I have a LiveTextBox that will do a database search on the TextChanged event. However, before performing this search, I want to pop up a message to the user that says "Searching; please wait..." using JavaScript and a DIV tag.

Before using LiveTextBox, I had code like this in the OnLoad event for the user control:

TextBox1.Attributes.Add("onchange", "PopWaitMsg();")

In effect, the LiveTextBox creates its own onchange event code and the resulting HTML output includes two onchange events, instead of one with multiple commands.

I read another post about something with IFRAMES, but I don't think that applies to my case.

I've also read about using the BufferedScript.Write property, but that fires AFTER my search is completed.
John Talarico



From: Rome, NY USA
Posts: 630
Member Since: 06/01/05
posted June 27, 2006 5:53 PM

With LiveControls adding an additional onchange event attribute to the element will interfere with the callback, as you have seen.

For scenarios such as this you can utilize the WaitElementID and WaitMessage properties of the LiveTextBox. The WaitElementID is the ID of the control on the page that you want to contain the 'Searching' message, ideally an empty LiveLabel.

The WaitMessage property is the text that you want to display while the callback is executing. This text can be HTML such as a DIV with contents or an IMG tag that points to an animated GIF file.

If you want the LiveTextBox to be disabled while the callback is executing, set the Blocking property to true.

The BufferedScript property is used for executing client script constructed in code-behind, after a callback is performed. 

Another alternative is to implement a function in client script with the name "pwBeforeCallback". This will be called before every callback on the page, so it is not exactly suited for this type of application. But, this is another way to execute client script before a callback raises a server event. Implementing a "pwAfterCallback" similarly executes whenever a callback completes.

Finally, if you want complete control over what is executed on the client before and after the callbacks raise server events, you can forego using a LiveTextBox and use a standard HTML text input element, client script and the LiveCallback control.
RyanH

From: Ottawa, ON Canada
Posts: 29
Member Since: 06/27/06
posted June 28, 2006 4:24 PM

I'm trying to use the LiveCallback control. Could you tell me what the third and fourth parameters of the pwBeginCallServerFunction function are? I can't seem to find any documentation on it. Thanks!
RyanH

From: Ottawa, ON Canada
Posts: 29
Member Since: 06/27/06
posted June 29, 2006 1:48 PM

I have gotten it to work using regular Textboxes, along with the LiveCallback control, custom JavaScript functions and pwBeginCallServerFunction, etc. When a search string is entered in one of the TextBoxes, the JavaScript pops up a custom "waiting" message and does a search. If the correct information is found, the search string is changed into the correct information and the TextBox is disabled.

However, if the user needs to change any information, s/he must click on a LiveLinkButton, which re-enables (and blanks out) the Textbox. Now, if the user types in there again to do a new search, the event (OnChange) no longer gets fired like it did the first time.

As far as I can tell, there is no postback/refresh taking place so I don't understand why the event doesn't get fired anymore. Any ideas? Thanks!
RyanH

From: Ottawa, ON Canada
Posts: 29
Member Since: 06/27/06
posted June 29, 2006 4:31 PM

It seems that a LiveLinkButton, when clicked, stops all the other Live controls amongst other things from functioning. I solved the problem by using a LiveButton instead.
John Talarico



From: Rome, NY USA
Posts: 630
Member Since: 06/01/05
posted June 29, 2006 7:24 PM

Yes, the LiveCallback was designed to be used with custom script code and manually written event handlers. It provides the most control over the client-side activity, but also requires the most work. It is provided as an advanced option for those developers who wish to take advantage of the LiveControls callback infrastructure, but not the built-in behaviors.

The third and for parameters of the pwBeginCallServerFunction are the Context and Blocking, respectively. If you set the Context parameter, on the callback, this value will be available in the response to assist you with correlating calls with responses. For example, in this client-side code I am executing the server-side DoSearch method and storing "ABC" in context. In the response, I can get access to it with the context property of the intrinsic pwRsCallbackResponse object passed to the searchComplete function called when the callback returns.

function doTextSearch()
{
var txt = document.getElementById("txtSrch").value;
document.getElementById("waitImage").style.visibility = "visible";
pwBeginCallServerFunction("DoSearch", "searchComplete", "ABC", false, txt);
}
function searchComplete(pwRsCallbackResponse)
{
alert(pwRsCallbackResponse.context);
document.getElementById("waitImage").style.visibility = "hidden";
}

The Blocking property determines if another callback is allowed while one is still being executed. If this property is true, the function will effectively force the LiveCallback to execute synchronously.

To address your other question about the onchange event not firing, this is entirely in the control of the browser when using standard HTML elements.  Ultimately, this will only fire when the content in the text box changes from the time it receives focus and when it loses focus. It sounds like something in the disabling/enabling code may be preventing this event from firing.

Lastly, I'm not sure about why the LiveLinkButton would cause the behavior you described. Can you isolate this to a separate form that does not use custom scripts and the LiveCallback?
RyanH

From: Ottawa, ON Canada
Posts: 29
Member Since: 06/27/06
posted July 24, 2006 2:44 PM

John, thanks for the reply. I will try to isolate the problem with the LiveLinkButton for you. This was just before 4th July weekend and it's summer... I've been outdoors.

I do have another question about the context parameter on the callback. In your example, you are passing "ABC" from the source function which is client JavaScript, to the destination function, also client JavaScript. However, I want to pass context information from the server side function and have that data available to the function specified as parameter 2, in your case searchComplete. Is this possible?
John Talarico



From: Rome, NY USA
Posts: 630
Member Since: 06/01/05
posted July 25, 2006 9:14 AM

I hope you're having a great summer outdoors. Sounds like fun.

The context parameter is used for correlating one callback with the same response on the client. FOr example, if you had two different source functions utilizing a single LiveCallback control and wanted to exhibit different behavior based on the calling function, you'd use the context parameter.

For passing data back from the server to the client, your server function must return a string, and the return string is accessed using (in my example) the pwRsCallbackResponse.data value.
RyanH

From: Ottawa, ON Canada
Posts: 29
Member Since: 06/27/06
posted July 25, 2006 9:31 AM

Hmmm, that would not be a clean solution for me. When the server function is called, this function may in turn call other functions or procedures. During all this processing, if an error occurs, I would normally catch the thrown exception and direct the execution flow to a routine to handle the error. I am not always able to find my way back up to the original function to properly return a value. This might require restructuring all the called functions to return a status.

Because of the absence of post-back now, I'm not able to handle reporting of the error in the same way, i.e. using Page.RegisterStartupScript to output JavaScript that would be executed on the postback. So, I was hoping to be able to somehow return an error status that the JavaScript could handle.

I know that I could use a LiveLable for error messages, but I have a long data entry screen and I want the error message to always pop up in the middle of the screen in the foreground. With a LiveLable, the user may not see the message at all.
RyanH

From: Ottawa, ON Canada
Posts: 29
Member Since: 06/27/06
posted August 8, 2006 2:43 PM

As for the LiveLinkButton, I think it wasn't working before because I didn't have

<httpModules><add name="CallbackManager" type="Dart.PowerWEB.LiveControls.CallbackManager,Dart.PowerWEB.LiveControls" /></httpModules>

in my web.config file. The control works fine now.
Reply | PowerWEB TextBox for ASP.NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX