I am very new to Ajax and have been impressed with reading about it and how you can refresh a area of a page and not the whole thing. I thought doing this when reading about it was fairly easy but I'm abit stuck on an area.
I have a Report-viewer on my page which uses a ScriptManager and I have a calendar control which when I click a day will need to refresh to put that into a Textbox.
The Report-viewer is on the page when it loads it needs to be passed a parameter but can only get that after they have selected something from a combobox
So this is what I have done so far:
<li>
<asp:UpdatePanel runat="server" ID="updateDOI">
<ContentTemplate>
<input id="txt_DateOfInterview" type="Date" class="aclass" runat="server" />
<asp:ImageButton runat="server" ImageUrl="~/Images/Calender.png" ID="calendericonDOI" CssClass="calendericonDOI ClanderDOI" OnClick="calendericonDOI_Click"></asp:ImageButton>
<asp:Calendar runat="server" ID="ClanderDOI" CssClass="ClanderDOI" OnSelectionChanged="ClanderDOI_SelectionChanged" BorderColor="#6a3d98" OnVisibleMonthChanged="ClanderDOI_VisibleMonthChanged">
<TitleStyle BackColor="Orange" />
</asp:Calendar>
</ContentTemplate>
</asp:UpdatePanel>
As you can see i have a wrapped a UpdatePanel around the calender and also the input box that will get populated with the day selected
And then with the report viewer I have done the same:
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<rsweb:ReportViewer ID="rvSickness" runat="server" BackColor="#6e4594" Font-Names="Arial" Font-Size="8pt" Height="100%" ProcessingMode="Remote" WaitMessageFont-Names="Arial" WaitMessageFont-Size="14pt" Width="450px" ShowCredentialPrompts="False" ShowParameterPrompts="False" ShowPromptAreaButton="True" ShowToolBar="true" ShowFindControls="False" ToolBarItemBorderColor="#FF9900" ToolBarItemHoverBackColor="#FF9900" ForeColor="White">
<ServerReport ReportServerUrl="" />
</rsweb:ReportViewer>
</ContentTemplate>
</asp:UpdatePanel>
But what I don't understand it that the ReportViewer is still refreshing when I do anything.
My question is why is the Report-viewer refreshing when I am selecting something from a calender control? Is it because it has not been passed a parameter yet or have I done something wrong?
what you can do is take two update panels
In first UpdatePanel in which i took a DropDownList(here i took some sample dropdown list items)
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" ClientIDMode="AutoID" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>one</asp:ListItem>
<asp:ListItem>two</asp:ListItem>
<asp:ListItem>three</asp:ListItem>
<asp:ListItem>four</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
Second update panel in which i took your ReportViewer
<asp:UpdatePanel runat="server" ID="UpdatePanel2" UpdateMode="Conditional">
<ContentTemplate>
<rsweb:ReportViewer ID="rvSickness" runat="server" BackColor="#6e4594" Font-Names="Arial" Font-Size="8pt" Height="100%" ProcessingMode="Remote" WaitMessageFont-Names="Arial" WaitMessageFont-Size="14pt" Width="450px" ShowCredentialPrompts="False" ShowParameterPrompts="False" ShowPromptAreaButton="True" ShowToolBar="true" ShowFindControls="False" ToolBarItemBorderColor="#FF9900" ToolBarItemHoverBackColor="#FF9900" ForeColor="White">
<ServerReport ReportServerUrl="" />
</rsweb:ReportViewer>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
Now in code behind you can pass the id to your ReportViewer on DropDownList1_SelectedIndexChanged event like this
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//your code here
}
Note: I didn't took you calendar and other controls in this answer as you wanted to update the ReportViewer only when you select an item from DropDownList
Related
The FileUpload and Button controls work fine by themselves. When I add the rest of the code as seen below for the UpdateProgress indicator, the FileUpload control is empty (PostedFiles.Count = 0) after selecting files and btnUpload. 'Loading...' displays ok. Something seems to reset FileUpload. Any ideas?
<asp:FileUpload ID="fuImageUploader" runat="server" AllowMultiple="True" BorderStyle="Inset" BorderWidth="1px" Font-Size="Larger" Height="24px" oninput="fuImageUploader_Click()" ToolTip="Select image file" ValidateRequestMode="Disabled" Width="391px" />
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" id="UpdatePanel1">
<ContentTemplate>
<asp:Button ID="btnUpload" runat="server" Height="26px" Text="Upload" Width="86px" OnClick="btnUpload_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress runat="server" id="PageUpdateProgress" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
Loading...
</ProgressTemplate>
</asp:UpdateProgress>
I use updatepanel in my page like this.
but when I run my app when I click on button that's refresh all of my page.
I do'nt know what I can do to solve this error.
even I use treeview in other page that when I get this error the treeview icon dont show.
please help me.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updPanl" runat="server" RenderMode="Block" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
try this
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="updPanl" ChildrenAsTriggers="true" runat="server" RenderMode="Block" UpdateMode="Conditional" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
protected void Button1_Click(object sender, EventArgs e)
{
updPanl.Update();
}
after three days I can find this problem today so I answer this question maybe this help to otherone.
I use routin in my app so webresource and scriptresouce could not load in asp page
I use this code for do not route this resource
routeCollection.Add(new Route("{resource}.axd/{*pathInfo}", new StopRoutingHandler()));
I have a gridview and inside that I have below code.
<asp:TemplateField HeaderText="Header 3">
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!-- only your content that needs refreshing goes here -->
<asp:Button ID="ButtonAdd" runat="server" Text="Add New Row"
onclick="ButtonAdd_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ButtonAdd" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</FooterTemplate>
</asp:TemplateField>
I have added update panel because when I click ButtonAdd button data in the gridview has been removed. But after I added below code button click event doesn't fire. Please suggest solution.
Please place your whole gridview inside update panel and remove update panel inside and try..
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gridview1" runat="server" >
</asp:GridView>
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
I have a gridview with a checkbox in first column. I set checkbox property of autopostback="true". The gridview is inside the updatepanel. When checkbox is checked i want to make one panel as visible, which panel is outside the update panel. I check the code with check point, which is go through the code, but its not working. Can any one help me?..
Thanks in advance.
My code is here for your reference...
HTML Code:
<asp:Panel ID="ploperation" runat="server" CssClass="plop" Visible="False">
<asp:LinkButton ID="lbtnasspam" runat="server" CssClass="panelbtn" Font-Names="Calibri"
Font-Size="14px" Font-Underline="False" OnClick="lbtnasspam_Click">Report As Spam</asp:LinkButton>
</asp:Panel>
<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
<asp:GridView ID="gvmail" runat="server" AllowPaging="True" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkchild" runat="server" AutoPostBack="true" OnCheckedChanged="chkchild_CheckedChanged"/>
</ItemTemplate>
<ItemStyle Width="15px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
C# Code:
protected void chkchild_CheckedChanged(object sender, EventArgs e)
{
ploperation.Visible = true;
}
You can use initializeRequest - this event is raised when an asynchronous post back occurs(When you check the checkbox in your gridview it initiates an async postback because it's inside an update panel).
Just change ploperation to a div instead of <asp:Panel and you can use javascript to show/hide it:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(initializeRequest);
function initializeRequest(sender, args) {
document.getElementById('ploperation').style.display = 'block';
}
</script>
<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
<asp:GridView ID="gvmail" runat="server" AllowPaging="True" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkchild" runat="server" AutoPostBack="true" />
</ItemTemplate>
<ItemStyle Width="15px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<div id="ploperation" style="display:none;" runat="server">
<asp:LinkButton ID="lbtnasspam" runat="server" CssClass="panelbtn" Font-Names="Calibri"
Font-Size="14px" Font-Underline="False" OnClick="lbtnasspam_Click">Report As Spam</asp:LinkButton>
</div>
</form>
Alternatively you can stick to the way you've done it, just place <asp:Panel inside UpdatePanel -> ContentTemplate
update panel does partial page loading....
check link
so if you want to show your panel than include it also in your update panel.
Put the UpdatePanel on the control you want to change, not on the GridView. Do not forget to Reference the GridView on the Triggers section. For example, if you want to change a label text use the following code:
<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvmail" />
</Triggers>
</asp:UpdatePanel>
<asp:GridView ID="gvmail" runat="server" AllowPaging="True" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkchild" runat="server" AutoPostBack="true" OnCheckedChanged="chkchild_CheckedChanged"/>
</ItemTemplate>
<ItemStyle Width="15px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
I have a listbox that is being updated via a timer and working as expected inside an UpdatePanel.
However I cannot get the selectedindexchanged event to fire. I presume this is something to do with the partial postback. Does anybody know what I can do to make this work?
When I move it out of the UpdatePanel it works fine. However obviously I cannot do partial postbacks.
<asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="500"></asp:Timer>
<asp:ListBox ID="ListBox_JobPositions" OnSelectedIndexChanged="ListBox_JobPositions_SelectedIndexChanged" runat="server" Height="750px" Width="300px" DataSourceID="sqlDataSource" DataTextField="Company" DataValueField="Pid"></asp:ListBox>
</ContentTemplate>
</asp:UpdatePanel>
UPDATE:
Have now tried the below change, the timer event is still working but the selectedindexchanged event is not. I am getting lost with this.
<asp:UpdatePanel ID="UpdatePanel" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="500"></asp:Timer>
<asp:ListBox ID="ListBox_JobPositions" runat="server" Height="750px" Width="300px" DataSourceID="sqlDataSource" DataTextField="Company" DataValueField="Pid" OnSelectedIndexChanged="ListBox_JobPositions_SelectedIndexChanged" AutoPostBack="True"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
Here is the event that does not fire when the listbox is inside the UpdatePanel but does work when it is not.
protected void ListBox_JobPositions_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("test");
}
The reason you are not getting the event is that, your change event is not causing the PostBack. Your postback is caused by the timer.
The event asp.net receives is the timer event and not the ListBox event.
To resolve the issue, you should set AutoPostBack to true. This will cause the ListBox to do a PostBack as soon as the data changes and your event should fire.
<asp:ListBox ID="ListBox_JobPositions" AutoPostBack="True"
OnSelectedIndexChanged="ListBox_JobPositions_SelectedIndexChanged"
runat="server" Height="750px" Width="300px"
DataSourceID="sqlDataSource"
DataTextField="Company"
DataValueField="Pid">
</asp:ListBox>
Since you have set the UpdateMode to Conditional, you should also set the ChildrenAsTriggers to true. This way way the List causes a PostBack, that too will be a partial update.
<asp:UpdatePanel ID="UpdatePanel" runat="server"
UpdateMode="Conditional"
ChildrenAsTriggers="True">
Works now, had to manually specify Async and Full Postback triggers. Thanks for your help.
<asp:UpdatePanel ID="UpdatePanel" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="500"></asp:Timer>
<asp:ListBox ID="ListBox_JobPositions" runat="server" Height="750px" Width="300px" DataSourceID="sqlDataSource" DataTextField="Company" DataValueField="Pid" OnSelectedIndexChanged="ListBox_JobPositions_SelectedIndexChanged" AutoPostBack="True"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
<asp:PostBackTrigger ControlID="ListBox_JobPositions" />
</Triggers>
</asp:UpdatePanel>