• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 452
  • Last Modified:

Update Panel - I know why not sure how to fix

I know why this is happening but not sure how to fix it.

I have a panel like this in an UpdatePanel:
<div id="pnlOrderItems" runat="server">
     <updatepanel>
           <asp:Button runat="server" ...>

I click on that button and I want to update a text on a linkbutton THAT IS OUTSIDE that updatepanel. Code is correct but i think because that textbox is outside the panel, that's why it doesnt get updated.

Anyway to do this? This is the linkbutton i want to update. The text remains as "No Data". If I come back to the page, it shows the correct text.

***If I make the linkbutton part of the updatepanel, then it works. I cant do this tho because of the position of the link button. It has to be on top.
<asp:Content ID="Content2" ContentPlaceHolderID="PageMenu" Runat="Server">
 
 
 <asp:Button ID="hlViewTranHistory"     Visible="false"   runat="server"/>
 <asp:Label ID="lblNoTransactions" runat="server"  Visible="false" Text="No Data."></asp:Label>
 
</asp:Content>

Open in new window

0
Camillia
Asked:
Camillia
  • 8
  • 7
  • 4
2 Solutions
 
GiftsonDJohnCommented:
On the button_click event on the server side, invoke a javascript function

ScriptManager.RegisterClientScriptBlock(Button1, Button1.GetType(), "changevalue", "document.getElementById('" + LinkButton1.ClientID + "').value='" + "value to be set" + "';", true);
0
 
silemoneCommented:
you can put the link button in its own update panel.  what does the linkbutton update?
0
 
silemoneCommented:
have the other button be the trigger for that update panel...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CamilliaAuthor Commented:
>> you can put the link button in its own update panel.  what does the linkbutton update?
I did that but the button wont display at all

>> have the other button be the trigger for that update panel...
How?

>> GiftsonDJohn:
I havent tried your method. I will
0
 
CamilliaAuthor Commented:
I tried the Javascript method. I put it in the grid's itemdatabound. Didnt work.

wrapped the button in another update panel. It just wont display.

I dont know what the 3rd method mean:  have the other button be the trigger for that update panel...
0
 
silemoneCommented:
like
<asp:Updatepanel....>
contentTemplate

<asp:linkbutton...>
</contentTemplate>
<triggers>
<asyncy...controlID = "OtherButton">


or you could set the updatePanel which holds the link button to: UpdateMode="Always"> since its only the button
0
 
CamilliaAuthor Commented:
let me try it. Thanks for responding again. thought u guys forgot.
0
 
CamilliaAuthor Commented:
didnt work. That "otherbutton" is inside a Grid. So, it cant be seen. I did below and got an error that btnProcess cannot be found
<asp:UpdatePanel runat="server">
  <ContentTemplate>
     <asp:Button ID="hlViewTranHistory"   Visible="false"   runat="server"/>
     <asp:Label ID="lblNoTransactions" runat="server"  Visible="false" Text="No View." ></asp:Label>
</ContentTemplate>
<Triggers><asp:AsyncPostBackTrigger ControlID="btnProcess" /></Triggers>
</asp:UpdatePanel>

Open in new window

0
 
GiftsonDJohnCommented:
Here you go.

Add Grid as control and RowCommand event for the trigger
0
 
CamilliaAuthor Commented:
>>Add Grid as control and RowCommand event for the trigger
not sure what u mean.
0
 
silemoneCommented:
i guess maybe you should give some background on what you're trying to do and why you implemented code this way if possible...
I didn't realize the button was in a grid until just now...
0
 
silemoneCommented:
anyway, are you binding data to the grid?  now this may get a little more complicated...

If you put your button inside of an updatepanel, you can use the PageRequestmanager...
Basically whenever a postback is made from an object inside of a UpdatePanel, PageRequestManager allows you to manipulate 4 stages of an asynch postback  which include the start and finish...

example links:  

http://stevenharman.net/blog/archive/2007/07/06/use-the-pagerequestmanager-to-get-more-control-of-your-updatepanels.aspx

so you would use something like this in your aspx page...this examples sets hourglass cursor while object saving...


<script language="JavaScript" type="text/javascript">
          var prm = Sys.WebForms.PageRequestManager.getInstance();
          prm.add_initializeRequest(InitializeRequest);
          prm.add_endRequest(EndRequest);        
          var executingItem = null;
         
          function InitializeRequest(sender, args) 
          {
            var postBackElement = args.get_postBackElement();
            executingItem = postBackElement;            
            
           
            if(postBackElement != null)
            { 
             
	         if (postBackElement == (document.getElementById("<%=Save.ClientID %>")))
	         {
	            document.body.style.cursor="wait";
	         }
	       }
	        
          }
          function EndRequest(sender, args) 
          {                
               document.body.style.cursor ="default";
          }

Open in new window

0
 
GiftsonDJohnCommented:
Instead of adding Button to the Trigger, since it is inside the grid, while clicking on the button it the grid will generate RowCommand event. So instead of button add grid to the trigger and declare the event to be executed as asynchronous is RowCommand
0
 
silemoneCommented:
giftson, that is another way that I agree should work...
0
 
silemoneCommented:
only thing if you can get it to work with javascript, it may be quicker...
0
 
CamilliaAuthor Commented:
>>  declare the event to be executed as asynchronous is RowCommand

so create a RowCommand for the Grid and in that RowCommand, update the control outside the updatepanel??
0
 
GiftsonDJohnCommented:
If you want an asynchronous update, both of them should be inside update panel.

<asp:UpdatePanel ID=UpdatePanel1>
<ContentTemplate
   <asp:Grid ID=Grid1> </Grid>
</ContentTemplate>
</asp:UpdatePanel

<UpdatePanel ID=UpdatePanel2>
<ContentTemplate>
<asp:Button ID="hlViewTranHistory"   Visible="false"   runat="server"/>
</ContentTemplate>
<Triggers>
   <asp:AsyncPostBackTrigger ControlID="Grid1" EventName="RowCommand" />
  </Triggers>
</UpdatePanel>
0
 
CamilliaAuthor Commented:
when I put Button ID="hlViewTranHistory"  inside an updatepanel, it disappears. Not sure why. So, I want it outside the updatepanel. What is that "RowCommand" method you mentioned?
0
 
CamilliaAuthor Commented:
wroks now. Thanks you both.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 8
  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now