Hi!
Can someone please point me to the a place, where Behaviours are explained? I found that some controls have custom behaviours and I found a client side Behaviours class.
I'd like to modify the onkeypress handler of a asp:TextBox control -- is Behaviour the right place to do so?
Thanks,
Miha.
mihav:
Hi!
Can someone please point me to the a place, where Behaviours are explained? I found that some controls have custom behaviours and I found a client side Behaviours class.
It is covered in the docs and explained with code by long time AJAX user Garbin. Hope this helps.
http://ajax.asp.net/docs/ClientReference/Sys.UI/BehaviorClass/default.aspx
http://aspadvice.com/blogs/garbin/archive/2006/01/23/14786.aspx
Thanks. The Garbin's post looks helpful -- the Behaviour class documentation is useless (I found that before) in helping understand what Behavirours are all about.
I'd like to change the the onkeypress event handling of the TextBox control to do a postback on every keypress... I hope behaviours are the right direction to go to?
Thanks,
Miha.
What you want is easier with JavaScript per the thread below, if you choose to use AJAX search Garbin's blog for all related posts and modify the code as needed. Hope this helps.
http://forums.asp.net/thread/1348454.aspx
Thanks. I pretty much solved the problem with "ordinary" input type=textbox field and a javascript event handler. I did find out, though, that if I remove the <asp:TextBox> from the page (although I am not using it) the __doPostback updates the whole page, not just the UpdatePanel content. To explain better:
Page has an ordinary text box andasp:TextBox on it. Both text boxes are outside of the update panel. Within an Update panel, there is a AsyncPostBackTrigger, referring to asp:TextBox control (which I amnot using). When I use the ordinary text box, everything works (meaning that the updates only affect update panel). So, if I remove the AsyncPostBackTrigger, the __doPostBack, triggered by ordinary textbox updates the whole page. If I try to wire AsyncPostBackTrigger with ordinary textbox, I get an error
A control with ID 'SearchBox' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
Because there is no control. (it is just markup...). Is there a way to wire ordinary form field (not asp.net control) with updatepanel?
Miha
hello.
Triggers are only meant to be used with server side controls. if you have a regular HTML control which starts a postback, then you can try to add the client id of that control to the _asyncPostbackControlsIDs collection maintained by the pagerequestmanager object.
Luis, can you please help me with _asyncPostbackControlsIds collection? Where do I find it? The PageRequestManager does not seem to have it. I've put a script block at the end of the aspx file and I got an undefined value for _asyncPostbackControlsIds.
Aha, I found out it is a typo. But nontheless, the code doesn't work. There must be another way to register this HTML control with pagerequest manager object. The code I tried is:
var prm = Sys.WebForms.PageRequestManager.getInstance(); prm._asyncPostBackControlIDs.add('SearchBox');Thanks, Miha.
Sorry. I'm a bit rusty with javascript.
So, I added it to the array.
If I remove the trigger <asp:AsyncPostBackTrigger ControlID="SearchBoxx" EventName="TextChanged" /> from the <triggers> in aspx, the array size decreases to 0, and is 1 after I add the 'SearchBox' HTML control to it. It still doesnot work, because it now refreshes the whole page again. There is something missing to this story. Something to tell the pagerequest manager to only update the updatepanel? The markup generated for the textboxes isidentical in both cases. The only difference on the page is this:
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tUpdatePanel1'], ['SearchBoxx'], [], 90);
When there is no <trigger> present, the second parameter is empty. And I tried to add that to a script at the end of the ASPX file, but it still refreshes the whole page...
Aaaaa. I would really like to get rid of the asp:TextBox control, as it is doing nothing on the page...
Miha
hello.
try running this:
<%@. Page Language="C#" AutoEventWireup="true" %>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (ScriptManager1.IsInAsyncPostBack &&
Request.Params["__EVENTTARGET"] == "txt")
{
panel.Update();
}
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script>
function main()
{
// Add Client Code here
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager
<asp:updatepanel runat="server" id="panel" UpdateMode="Conditional">
<ContentTemplate>
panel 1:
<%= DateTime.Now.ToString() %>
</ContentTemplate>
</asp:updatepanel>
<asp:updatepanel runat="server" id="Updatepanel1" UpdateMode="Conditional">
<ContentTemplate>
panel 2:
<%= DateTime.Now.ToString() %>
</ContentTemplate>
</asp:updatepanel>
<input type="text" id="txt" onchange="__doPostBack('txt','');"; />
</form>
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded( function() {
Sys.WebForms.PageRequestManager.getInstance()._asyncPostBackControlClientIDs.push( "txt" );} );
</script>
</body>
</html>
Luis, this is excellent. It works. I'll see what changes I have to make to make my example work and I'll post the solution to my problem (should someone else have the same problem).
Tnx,
Miha.
3 months later, and out of AJAX RC, the solution to this problem was this:
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded( function() {
Sys.WebForms.PageRequestManager.getInstance()._asyncPostBackControlClientIDs.push( "txt" );} );
Thanks again,
Miha.
No comments:
Post a Comment