I have 2 pages each with an update panel. It has the same content and the same trigger on both pages.
This is how it looks:
<div id="rating">
<span class="rateTxt">Rate</span>
<telerik:RadRating ID="RadRating1" runat="server" ItemCount="5" SelectionMode="Continuous"
Precision="Item" Skin="Default" OnRate="RadRating1_Rate" AutoPostBack="true">
</telerik:RadRating>
</div>
</li>
</ul>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<div id="divAddMessage" runat="server" visible="false">
<span class="rateTxt">Do you want to add a comment?</span>
<asp:TextBox runat="server" ID="txtComment" TextMode="MultiLine" Rows="3" Width="195">
</asp:TextBox>
<br />
<br />
<asp:ImageButton runat="server" ID="lnkAddComment" ImageUrl="~/App_Themes/123reg/Images/submit-rating.png"
OnClick="lnkAddComment_Click" OnClientClick="showSuccessMessage();" />
<br />
<br />
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RadRating1" EventName="Rate" />
</Triggers>
</asp:UpdatePanel>
Now when the user rates something with the RadRating the Rate event is triggered which causes a postback.
On the handler for the Rate event I do the following:
protected void RadRating1_Rate(object sender, EventArgs e)
{
divAddMessage.Visible = true;
}
The same code is exactly on 2 pages. On one page it updates the divAddMessage and it becomes visible but on another page it doesn't become visible. Even if I set it to visible on that page when it postback again the Visible property is still false even after setting it to true in the above handler.
I only set the visibily to false in the aspx file and in the above handler I set it to true.
It turns out that I get an error in the javascript console:
Sys.InvalidOperationException: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_mainContentPlaceHolder_updatePanel'. If it is being updated dynamically then it must be inside another UpdatePanel.
I have another update panel inside a multiview. But because the active view is not the one with the update panel on postback the update panel isn't rendered.
Check the parent/container elements for divAddMessage. Have they got their Visibility set to false. If so then the child element will always be Visible=false even if you have set it explicitly to true. That's driven me mad in the past.
Just a thought
I had a custom control and had set the Visible property to false on declaration in the aspx file and that was overriding the visibility of any child elements within the control itself.
Related
ASP.NET radio button is not visible in my page. I am using it inside ASP.NET ListView. I tried putting the radio button inside ASP.NET update panel content template as well. Please tell me what has gone wrong?
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:ListView ID="FraudCheckList_listView" runat="server">
<ItemTemplate>
<p class="fraud-step-title"><%#Eval("question")%></p>
<div class="row">
<asp:RadioButton
runat="server"
class="radio-inline col"
GroupName="govt"
Text="Low Risk"
></asp:RadioButton>
<asp:RadioButton
runat="server"
GroupName='govt'
Text="Medium Risk"
></asp:RadioButton>
<asp:RadioButton
runat="server"
GroupName='govt'
Text="High Risk"
></asp:RadioButton>
</div>
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
Since you haven't shared how your code looks like, i am just assuming certain things. Just see if you have done this or not.
void Button_Click(object sender, System.EventArgs e){RadioButton.Visible=false;}
If incase its true or something your radiobutton will not be visible. In your case it must be hidden. So, make the variable of visible as **false ** So you can just change your code to this and try it out.
This you have to do it in your main code. not in your html code.
Thank You!
I have a simple command event that toggles the visibility of two buttons.
When the controls are wrapped in an update panel as below, each subsequent click does not toggle the visibility of the buttons even though the code executes as expected.
Testing
The code works as expected when the update panel is removed.
After clicking the button refreshing the page reflects the changes made.
The issue clearly lies with refreshing the content after a postback.
I have tried upd.update and updateMode="always"
ASPX
<asp:UpdatePanel ID="upd" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="rpt" runat="Server">
<ItemTemplate>
<asp:Button ID="btnOn" runat="Server" Text="ON" CommandName="ON" CommandArgument='<%#: Container.ItemIndex%>' UseSubmitBehavior="false" />
<asp:Button ID="btnOff" runat="Server" Text="OFF" CommandName="OFF" CommandArgument='<%#: Container.ItemIndex%>' UseSubmitBehavior="false" />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
VB.NET
Protected Sub Page_PreRenderComplete(sender As Object, e As EventArgs) Handles Me.PreRenderComplete
For Each item In rpt.Items
'Do a check and set output'
btnOn.Visible = Not Output
btnOff.Visible = Output
Next
End Sub
So, I have an event that is fired always when a text file is updated. This is the event handler:
private void FileWasChanged()
{
this.runsList.Items.Clear();
runningModels = RunsFile.ReadFile(Constants.active_runs_loc, Constants.run_file_name);
this.runsList.DataSource = runningModels;
this.runsList.DataBind();
this.updatePanel.Update();
}
Within this method I am clearing the ListView (runsList), reading the contents of the file and then binding the new data to the ListView. The updatepanel is then updated. But that does not happen, the page stays static until I press F5. Here's the layout:
<section>
<asp:ScriptManager ID="scriptManager1" runat="server" ></asp:ScriptManager>
<asp:UpdatePanel id="updatePanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:ListView ID="runsList" runat="server">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li>
<asp:Label Text="<%# Container.DataItem %>" runat="server" />
</li>
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger controlid="runsList"/>
</Triggers>
</asp:UpdatePanel>
</section>
So I am trying to give the user of the web site real time information from the text file. For example, when I change a line in the text file, that line should be added to the web page. The event itself works fine (tested with break points and console project), but for some reason the async update does not do anything.
I tried to look for similar problems, but everyone is using a button for the asyncpostbacktrigger. However, I am very new to C# so I may be misunderstanding how UpdatePanel and ListView DataBind work.
Any help appreciated!
Cheers,
Tetsii
Edit: The FileWasChanged is a handler that is called from FileSystemWatcher OnChanged event. The handler updates the view if called from Page_Load or an async button trigger.
I want to create a dynamic form where user has a button to click on it.
When the button clicked, it will trigger a partial postback and add a new control into a placeholder.
My problem is, when the button is clicked for the first time, it able to create a new control in the placeholder. But it will not create more than that even though i have clicked the button for few times.
<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Add images" OnClick="Button1_Click" />
<asp:HiddenField ID="HiddenField1" runat="server" Value="1" />
<br />
<asp:Panel ID="PlaceHolder1" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Code behind:
protected void Button1_Click(object sender, EventArgs e)
{
PlaceHolder1.Controls.Add(new FileUpload());
}
Unless a dynamically added control is added at the preinit or init stage, it does not persist beyond a post back. So when the button is clicked for the second time, the first added control is lost and then the button logic adds a control again, leaving you with one control every time. For a control added after the init stage, you would need to store its state and recreate it on each postback. This is described int this article:
http://www.codeproject.com/Articles/3684/Retaining-State-for-Dynamically-Created-Controls-i
You may also be able to achieve your goals without using dynamically added controls. One possible approach is to use a ListView control, add a FileUpload control to its ItemTemplate and add a new record to the list view data source every time the button is clicked.
My content page
<asp:updatePanel id="Panel1" runat="server" Visible="true">
<ContentTemplate>
<div>
blah blah
</div>
</ContentTemplate>
</asp:updatePanel>
<asp:updatePanel id="Panel2" runat="server" Visible="false">
<ContentTemplate>
<div>
yada yada
</div>
</ContentTemplate>
</asp:updatePanel>
Code file ..The following code is at the end of Submit button click event :-
Panel1.Visible = false;
Panel2.Visible = true;
Now earlier I was using asp:Panel..then it was working fine..like Panel 1 would hide and Panel 2 would show up instead..it was AFTER I changed asp:Panel to asp:updatePanel that things got screwed up...now the Submit button just won't work !!
What's gone wrong suddenly ?? I changed it to updatePanel so the page doesn't refresh..isn't this how we implement this thing ???
<asp:updatePanel id="Panel1" runat="server">
<ContentTemplate>
<div>
<p>
Type ur name
<asp:TextBox ID="name" runat="server">
</asp:TextBox>
</p>
<asp:Button ID="btn" OnClick="btn_Click" runat="server"
Text="Submit" />
</div>
</ContentTemplate>
</asp:updatePanel>
<asp:updatePanel id="Panel2" runat="server" Visible="false">
<ContentTemplate>
<div>
Thank You!
</div>
</ContentTemplate>
</asp:updatePanel>
At http://msdn.microsoft.com/en-us/magazine/cc163413.aspx#S3 , you can read
Multiple UpdatePanels
A page can host several UpdatePanels. By default, when one UpdatePanel on a page updates, the other UpdatePanels on the page also update. Sometimes that’s what you want, but more often than not, you don’t need every UpdatePanel updating in response to other UpdatePanels.
You can be selective about which UpdatePanel instances update (and when) by setting the UpdateMode property of each UpdatePanel control on the page to "Conditional." Then, when one UpdatePanel updates and calls a server-side event handler, call UpdatePanel.Update on the other panels you want to update. This reduces the load on the server by reducing the number of controls that render, and it reduces the volume of data in the response because UpdatePanels that don’t update don’t add anything to the response.
If you set Visible="false" on an UpdatePanel, it won't be rendered to the client at all. Therefore, if you're doing an Ajax postback, the client isn't going to be able to make the invisible UpdatePanel visible, because it just isn't there.
Think of UpdatePanels just as markers, showing which bits of your page you want to update on an Ajax postback. For your scenario, I think the easiest solution would be to use both UpdatePanels and Panels. Also, because the two things you're updating (the two Panels) are right next to each other, there's no need for two separate UpdatePanels:
<asp:updatePanel id="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel id="Panel1" Visible="true" runat="server">
blah blah
</asp:Panel>
<asp:Panel id="Panel2" Visible="false" runat="server">
yada yada
</asp:Panel>
</ContentTemplate>
</asp:updatePanel>
Then in the code-behind, change the Visible property on the Panel controls.
I do not know where your Submit button is, but maybe try updating those panels with:
Panel1.Update();
Panel2.Update();