Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
ASP.NET
<asp:TextBox ID="TextBox8" runat="server" Width="268px"  
                        onChange="$find('AutoCompleteExtender3').set_contextKey(this.value);" 
                        ontextchanged="TextBox8_TextChanged" AutoPostBack="true"></asp:TextBox> 


This is my code
Please notice the
HTML
AutoPostBack="true"

and
HTML
onChange="$find('AutoCompleteExtender3').set_contextKey(this.value);"


My autpostback is not working because of onchange event.

If I remove the onchange event then its working perfectly.
Please suggest any alternative way, Because I need both of them.
Please help.
Posted
Updated 5-Jan-13 5:41am
v2

you might try

XML
<asp:TextBox ID="TextBox8" runat="server" Width="268px"
        onChange="$find('AutoCompleteExtender3').set_contextKey(this.value); __doPostBack('TextBox8','');"
        ontextchanged="TextBox8_TextChanged" AutoPostBack="true"></asp:TextBox>


This should, in theory, force the postback after the set_contextKey is called. I haven't tested this though, so let me know if it doesn't work.
 
Share this answer
 
Comments
[no name] 5-Jan-13 12:49pm    
Thanks for reply
but the code is not working for me.
No Error, but the output is as previous, autopostback is not working
Please help
Hi,

You can try one other thing, instead of putting everything like this below -
ASP.NET
<asp:TextBox ID="TextBox8" runat="server" Width="268px"
        onChange="$find('AutoCompleteExtender3').set_contextKey(this.value); __doPostBack('TextBox8','');"
        ontextchanged="TextBox8_TextChanged" AutoPostBack="true"></asp:TextBox>


I suggest you try the below alternative -
first add a script tag in your page & put the javascript content in a function & then call this function (as below). Also add a return true in the function -
ASP.NET
<script>
function AutoCompleteExtend()
{
  $find('AutoCompleteExtender3').set_contextKey(this.value);
  return true;
}
</script>

<asp:TextBox ID="TextBox8" runat="server" Width="268px"  
                        onChange="javascript:return AutoCompleteExtend();" 
                        ontextchanged="TextBox8_TextChanged" AutoPostBack="true"> 

Again please note this hasn't been tested. Kindly request you to test this & let me know ...

Regards
 
Share this answer
 
v2
Comments
[no name] 6-Jan-13 13:30pm    
No,
Not working!
Same problem exist
No Autopostback.
Try this:
ASP.NET
<asp:textbox id="TextBox8" runat="server" width="268px" onchange="$find('AutoCompleteExtender3').set_contextKey(this.value); return true;" ontextchanged="TextBox8_TextChanged" autopostback="true" xmlns:asp="#unknown"></asp:textbox> 



--Amit
 
Share this answer
 
Comments
[no name] 6-Jan-13 13:27pm    
Thanks for the answer
But Not working
Sorry
Just the idea: you can choose to remove auto postback and write explicit Ajax post in your handler of your OnChange event handler.

I would perfectly understand that you want both the postback and this event. Probably, you first do some local processing on the client side using this event and newly updated value of the text box (entered text) with JavaScript, and then you need to notify the server by sending the HTTP request. When HTTP server processes the request, new updated part of page is generated out of HTTP response and the cycles starts over.

If this is your scenario, it can be quite reasonable; this is what Ajax is actually used for. At the same time, I would advise you to review it, as the event OnChange can be too frequent. You need to consider performance cost of the exchange with the server on each event. Overuse of Ajax is actually a curse of many present-days site: developers make them actually working, but they don't care about how much it costs due to wildly redundant traffic use.

Nevertheless, if you still decide to keep to having both client-side event handling and postback on each event, you can remove auto postback and send Ajax HTTP request in the JavaScript code of you event handler. One of the possible ways to do it is using jQuery Ajax methods. Please see:
http://api.jquery.com/category/ajax/[^].

Good luck,
—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900