views:

813

answers:

3

I have and Update Panel with a Grid inside of it. The grid's data will depend on a what a user

inserts into a Search textbox. They will click Search and on clientside the grid slides in via

some Ajax animations i used. My issue is the I want the grid to reload with the text in the

search box as it's parameter data. How do I reload that Grid's Update Panel on click of that

button?

<font color="blue">Search:</font><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/bttnSearch.gif" Height="19" />
</p>
<div id="moveMe" style="display:">
    <div style="float:right;">
    <asp:LinkButton ID="lnkBtnCloseColHelp" runat="server" Text="X" OnClientClick="return false;" />
  </div>
<br /><br />
<center>
     <table>
     <tr>
        <td>
             <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
             <ContentTemplate >
                    //Gridview and SqlDatasource goes here.
             </ContentTemplate>   
              <Triggers>
                <asp:AsyncPostBackTrigger ControlID = "ImageButton2" EventName = "Click"/>
             </Triggers> 
             </asp:UpdatePanel>

My Grid won't load because It needs to get that data in the textbox. Should that textbox be inside of the updatepanel also? Any Ideas on how i can get the Grid alone to reload based on the textbox's text after the search button is hit.

A: 

Yeah, this is a little vague, so my answer will be as well. You will have to handle the click event of the image button in your code behind. At that point you will need to rebind the gridview with the updated results.

fizch
Ok...but won't this fire off a complete postback if i handle this in code?
Eric
it will postback the data from the controls within the updatepanel
fizch
+1  A: 

How about 'hacking' this way. Have a dummy hidden textbox or hidden field control within the UpdatePanel. Perform a client-side copy of the actual textbox value to the hidden control when the button is clicked. Not elegant but should work.

Additional Info: If the trigger is set as AsyncPostBack:

    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Button1">
        </asp:AsyncPostBackTrigger>
    </Triggers>

The postback actually gets the values of all the controls outside the UpdatePanel. So my hack is not required at all.

o.k.w
Ok, I like this idea,but how do i reload just the gridview inside the update panel.
Eric
@Eric Hmmm, your trigger is the button and the UpdatePanel should be 'refreshed' upon clicking the button, yea? I assume your initial problem was not able to capture the value of the textbox?
o.k.w
Well regardless if the textbox is empty or not there is data in the grid...so i can see that the trigger isn't working....
Eric
is it because I have onclientclick="return false;" but if i remove this the whole page will reload
Eric
Try adding the EventName to your trigger and remove the onclick="return false"<asp:AsyncPostBackTrigger ControlID="ImageButton2" EventName="Click" />
o.k.w
Also, just realised you are using asp:PostBackTrigger and instead of asp:AsyncPostBackTrigger. Give it a try, it works for me.
o.k.w
It works...but it reloads the entire page.
Eric
when i say it works i mean that it sets the parameter to the correct value
Eric
@Eric, you meant the entire page is reloaded even when using AsyncPostBackTrigger?
o.k.w
Yes. for some reason...it reloads the entire page. I will update the code I have above.
Eric
I got it!. Thanks I had to put onclientclick="return true;"
Eric
A: 

You can probably put both of those sections in different update panels.

You can have one update panel containing the search box input and image button, and another one containing your grid control.

Min
didn't work because of the fact that the button is an extender
Eric
Well... That's usually because the DOM objects are actually removed. The extender code I think only runs once the page is initialized. In order to get the extender to keep running the Sys.Webforms.PageRequestManager has to be used. http://www.asp.net/Ajax/Documentation/Live/ClientReference/Sys.WebForms/PageRequestManagerClass/defaultOr to keep myself sane.... I use jQuery Live when dealing with stuff like this
Min