Updating a control outside the UpdatePanel - asp.net

I have the following ASPX structure:
<UpdatePanel id="OutsidePanel" UpdateMode="Conditional">
<div runat="server" id="myDiv">
<UpdatePanel id="InsidePanel" UpdateMode="Conditional">
<asp:ImageButton that causes a postback.. />
</UpdatePanel>
</div>
</UpdatePanel>
When the imageButton is clicked, on the server side, I change the class of myDiv. It's not getting updated. I assume this is because the div is outside of the Inside UpdatePanel. How would I force it to update?

Could you not just call the Update method of the "OutsidePanel" UpdatePanel on the server when the Imagebutton in "InsidePanel" causes a postback? Or alternatively, set up ImageButton click event as a trigger for "OutsidePanel"
According to MSDN
If the UpdateMode property is set to
Conditional, the UpdatePanel control's
content is updated in the following
circumstances:
When you call the Update method of the UpdatePanel control explicitly.
When the UpdatePanel control is nested inside another UpdatePanel
control, and the parent panel is
updated.
When a postback is caused by a control that is defined as a trigger
by using the Triggers property of the
UpdatePanel control. In this scenario,
the control explicitly triggers an
update of the panel content. The
control can be either inside or
outside the UpdatePanel control that
the trigger is associated with.
When the ChildrenAsTriggers property is set to true and a child
control of the UpdatePanel control
causes a postback. Child controls of
nested UpdatePanel controls do not
cause an update to the outer
UpdatePanel control unless they are
explicitly defined as triggers.

If you are updating the class server-side, then the answer is yes. The inner update panel is being rerendered and passed back to the client, but the outer update panel is not being replaced. Anything outside the actual panel being updated won't be replaced when the AJAX callback returns. You might want to consider adding some javascript that updates the div when the result is returned as a simple solution to changing the class.

Related

update panel does not working for views

i am using updatepanel for a linkbutton so that it doesnot refresh the whole page . on click of that linkbutton i need to set an active view in a multiview control which is working fine without updatepanel.
but when i use updatepanel it doesnoot work. can you help me how to do this
updatepanel code
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:LinkButton ID="changephoto" runat="server" ForeColor="Blue" OnClick="changephoto_Click">Change Photo</asp:LinkButton><br /><br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="changephoto" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
on click event
Protected Sub changephoto_Click(ByVal sender As Object, ByVal e As System.EventArgs)
MultiView_Updates.SetActiveView(View_ChangePhoto)
'bindprofileimage()
End Sub
put the multiview inside the updatepanel.....
If you want set view on click of the linkbutton which is placed inside the update panel, then your Multiview must also be present inside the update panel. Otherwise, the control will not be refreshed.
UpdatePanel controls work by specifying regions of a page that can be updated without refreshing the whole page. An asynchronous postback behaves like a regular postback in that the resulting server page executes the complete page and control life cycle. However, with an asynchronous postback, page updates are limited to regions of the page that are enclosed in UpdatePanel controls and that are marked to be updated. The server sends HTML markup for only the affected elements to the browser.
Using Nested UpdatePanel Controls
UpdatePanel controls can be nested. If the parent panel is refreshed, all nested panels are refreshed also.
The following example shows markup that defines an UpdatePanel control inside another UpdatePanel control. A button in the parent panel triggers an update of the content in both the parent and the child panel. The button in the child panel triggers an update of only the child panel.

ASP.NET Page_PreRender method

I'm trying to set a htmltablecell.innerHTML from code behind on Page_PreRender.
It works fine the first time it's set.
Hereafter I need to set the reference to a new value from a string (I have checked that the string value is changed), but it keeps displaying the old value in the HTML output.
When I debug the htmltablecell.innerHTML, I can also see that the value has changed.
The reason why the value is set from Page_PreRender method, is that I have a User Control which updates the string after the Page_load has fired.
What you desribe can occur, if the post back is asynchronous (fired from a control in an UpdatePanel) when the control being accessed, (the HtmlTableCell in this case) is outside the UpdatePanel.
Disregard if this is not the case.
Edit
You have two options.
You can setup the control within the UpdatePanel which is initiating the async postback to perform a standard postback. To do this, define a PostBackTrigger within the UpdatePanel, setting the ControlID to the ID of the control you wish to perform the postback.
(Because this will be performing a full postback, the HtmlTableCell will then be accessible to modify)
<asp:UpdatePanel ... >
...
<Triggers>
<asp:PostBackTrigger ControlID="ControlIDToPostBack" />
</Triggers>
</asp:UpdatePanel>
Or you could add the HtmlTableCell (and parent rows, table etc) you wish to update to another UpdatePanel setting both of the UpdatePanel's UpdateMode properties to Always.
This will ensure that the content within both UpdatePanel controls is updated for all postbacks that originate from the page. Which includes asynchronous postbacks.
<asp:UpdatePanel ... UpdateMode="Always">
Hope this helps.

How do I force asp.net page to postback when I'm in code behind that called by UpdatePanel

When an UpdatePanel Calls a method in server and for example this method change
textBox1.Text = "12312"
and this textBox1 was out of updatePanle scope
it dosn't change it text till a postback happend to the page
so I need after that calculation and chaging the Textbox's text in the server, I need to forcepage to do postback
plz can any one help ?
If you want to force a refresh you could try: Response.Redirect(Request.Url.AbsoluteUri)
This should force a redirect to the current page.
Hope this helps
If you wish for a control within the UpdatePanel to perform a standard postback, define a PostBackTrigger within the UpdatePanel, setting the ControlID to the ID of the control you wish to perform the postback.
<asp:UpdatePanel ...
...
<Triggers>
<asp:PostBackTrigger ControlID="ControlIDToPostBack" />
</Triggers>
</asp:UpdatePanel>
Or you could add the TextBox control you wish to update to another UpdatePanel setting both of the UpdatePanel's UpdateMode properties to Always.
This will ensure that the content within both UpdatePanel controls is updated for all postbacks that originate from the page. Which includes asynchronous postbacks.
<asp:UpdatePanel ... UpdateMode="Always"

Refresh a control on the master page after postback

What i am trying to do here is to show a couple of validation messages in form of a bulletlist, so i have a Div on my master page containing a asp:bulletlist. Like this:
<div>
<asp:BulletedList ID="blstValidationErrorMessage" runat="server" BulletStyle="Disc">
</asp:BulletedList>
</div>
When i then click the Save button from any of my pages (inside the main contentPlaceHolder) i create a list of messages and give this list as datasouce like this:
blstValidationErrorMessage.DataSource = validationMessageCollection;
blstValidationErrorMessage.DataBind();
The save button is located inside an updatepanel:
asp:UpdatePanel runat="server" ID="UpdatePanel" ChildrenAsTriggers="true" UpdateMode="Conditional">
Nothing happens, i can see that the datasource of the bulletlist contains X items, the problems must arise because the Save button is inside an update panel and the elements outside this updatepanel (master page controls for example) is not refreshed.
So my question is, how do i make the bulletlist refresh after the postback?
Thanks in advance.
If your button is inside an UpdatePanel, you should place your BulletedList control inside an UpdatePanel too.
You can place an UpdatePanel surrounding the BulletedList in the MasterPage file. Set "UpdateMode" to "Conditional" then call the Update method of the UpdatePanel to refresh only when needed ('save button' click for example).
The Save button will only update the contents of the UpdatePanel you placed it in. Here's what I recommend doing:
Move the SaveButton outside of the UpdatePanel. Where you put it I'll leave up to you.
Put your validation div inside another UpdatePanel. Call it ValidationUpdatePanel
Add your SaveButton as an AsyncPostbackTrigger for both update panels. Since you may have each UpdatePanel separated into different controls/pages, you'll probably want to do this in the code-behind programmatically.

Refresh update panel

i have master page update panel also. When i child page have delete function.
when i delete the row from grid. after i rebind the grid. Then also i cannot see refreshed grid.
how to update the panel or grid?
regards
Dhanraj.S
try the following:
ctype(me.Page.Master.FindControl("UpdatePanel1"),UpdatePanel).Update()
Setup your UpdatePanel like this:
<asp:UpdatePanel ID="UpdatePanel1" runat="server"
ChildrenAsTriggers="True" UpdateMode="Always">
<ContentTemplate>
...
</ContentTemplate>
</asp:UpdatePanel>
NOTE: GridView and DetailsView controls are not compatible with the UpdatePanel when their EnableSortingAndPagingCallbacks property is set to true. The default is false.
Using UpdatePanel Controls in Master Pages
UpdateMode Property :
The content of an UpdatePanel control is updated in the following circumstances:
If the UpdateMode property is set to Always, the UpdatePanel control's content is updated on every postback that originates from anywhere on the page. This includes asynchronous postbacks from controls that are inside other UpdatePanel controls and postbacks from controls that are not inside UpdatePanel controls.
If the UpdatePanel control is nested inside another UpdatePanel control and the parent update panel is updated.
If the UpdateMode property is set to Conditional, and one of the following conditions occurs:
You call the Update method of the UpdatePanel control explicitly.
The postback is caused by a control that is defined as a trigger by using the Triggers property of the UpdatePanel control. In this scenario, the control explicitly triggers an update of the panel content. The control can be either inside or outside the UpdatePanel control that defines the trigger.
The ChildrenAsTriggers property is set to true and a child control of the UpdatePanel control causes a postback. A child control of a nested UpdatePanel control does not cause an update to the outer UpdatePanel control unless it is explicitly defined as a trigger.

Resources