UpdatePanelTriggers TextBox.onKeyUp

M

mc

Can someone suggest how I would add a new trigger such that when the JS event onkeyup in a textbox
the updatePanel refreshes?

If not could someone sugest how I could onkepup in a Textbox, refresh the contents of a
gridview/repeater control?

TIA


MC
 
D

David R. Longnecker

MC-

Googling "updatepanel" and "javascript" will come up with various solutions.
Here's one I've picked apart from various blogs and forum posts that works
for me.

Here's what you'll need:

1. A javascript function to call __doPostBack.

2. A <asp:HiddenField /> inside your UpdatePanel that you want to update.
This helps "tag" the panel to ensure you're updating the correct one.

3. The onKeyUp javascript event on your TextBox control. Note: This will
throw a fit because VS2005 and Orcas do not recognize this as a valid event
for a TextBox (anyone know why or if that will change?).

In the Header of the page (or posted via Page.Header in codebehind), your
JavaScript will look something like:

<script type="text/javascript">
function updatePanelPostback()
{
__doPostBack("<%=upHiddenPostback.ClientID%>","");
}
</script>

This JavaScript will do a postback based on the ClientId of a hidden field
we'll add here in a moment.

Your TextBox control, the one you want to use to generate the onKeyUp event,
will call that JavaScript function.

<asp:TextBox ID="TextBox1" runat="server" OnKeyUp="javascript:updatePanelPostback();"
/>

Finally, your update panel will have an additional HiddenField tag.

<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true"
UpdateMode="Conditional">
<contenttemplate>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:HiddenField runat="server" ID="upHiddenPostback" />
</contenttemplate>
</asp:UpdatePanel>

Also, you can pass the HiddenField.ClientID as a parameter to your JavaScript
call to make it more reusable.

You can also tie this to any JavaScript event, like onClick, to force a specified
update.

HTH.

-dl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top