N
Nightcrawler
I hope this is the right group for this question.
I recently started looking into AJAX and I am doing the following:
I have a repeater (dummydata) that is bound to a datatable (Articles).
Each ItemTemplate in the repeater has an Label control that is showing
ArticleName and an UpdatePanel. The UpdatePanel contains another
Repeater. I also have a button above the repeater. Each UpdatePanel
has an AsyncPostBackTrigger setup to my Button with EventName Click.
What I want to happen is the following: The button is clicked and all
the UpdatePanels call a webservice passing the ArticleName with the
infromation from the Label. The webservice then returns a datatable
that is bound to the repeater within each UpdatePanel.
ASPX Code below:
My Button Code is listed below:
protected void UpdateAllButton_Click(object source, EventArgs e)
{
Button button = source as Button;
Repeater dummyData =
(Repeater)button.Parent.FindControl("DummyData");
foreach (RepeaterItem i in dummyData.Items)
{
Repeater repeater1 = (Repeater)i.FindControl("Repeater1");
Label articleLabel = (Label)i.FindControl("ArticleLabel");
ArticleFinderWebService t = new ArticleFinderWebService();
repeater1.DataSource = t.FindArticle(articleLabel.Text);
repeater1.DataBind();
}
}
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference
Path="TrackFinderWebService.asmx" />
</Services>
</asp:ScriptManager>
<br />
<asp:Button ID="UpdateAllButton" runat="server" Text="Button"
OnClick="UpdateAllButton_Click" /><br />
<asp:Repeater ID="DummyData" runat="server">
<ItemTemplate>
<table>
<tr>
<td width="300"><asp:Label ID="ArticleLabel"
runat="server" Text='<%# Bind("Article") %>'></asp:Label></td>
</tr>
</table>
<asp:UpdatePanel ID="InnerUpdatePanel" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table>
<tr>
<td width="20">
<asp:CheckBox
</td>
<td width="250">
<asp:Label ID="lblArticle"
runat="server" Text='<%# Bind("Article") %>'></asp:Label><br />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger
ControlID="UpdateAllButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
</asp:Repeater>
Now this code works fine but I have a few questions:
1. Is this the right way to do it? I guess I get confused when I use
ServerSide events to execute AJAX calls.
2. Let's assume I want a few webservices to be called (each webservice
grabs information about the article but from different sources on the
internet. Would it be better to use one webservice to go out and
collect data from different locations, put it in a datatable then
return it to the repeater in the updatepanel OR add another webservice
method and add another updatepanel in the ItemTemplate then have each
UpdatePanel call a different webmethod? I was thinking the latter
approach since everything will happen at the same time, and if one
webservice finishes before the other, that data will be displayed on
the page right away instead of having to wait and gather all the data
then present it.
Any feedback would be greatly appreciated.
Thanks
I recently started looking into AJAX and I am doing the following:
I have a repeater (dummydata) that is bound to a datatable (Articles).
Each ItemTemplate in the repeater has an Label control that is showing
ArticleName and an UpdatePanel. The UpdatePanel contains another
Repeater. I also have a button above the repeater. Each UpdatePanel
has an AsyncPostBackTrigger setup to my Button with EventName Click.
What I want to happen is the following: The button is clicked and all
the UpdatePanels call a webservice passing the ArticleName with the
infromation from the Label. The webservice then returns a datatable
that is bound to the repeater within each UpdatePanel.
ASPX Code below:
My Button Code is listed below:
protected void UpdateAllButton_Click(object source, EventArgs e)
{
Button button = source as Button;
Repeater dummyData =
(Repeater)button.Parent.FindControl("DummyData");
foreach (RepeaterItem i in dummyData.Items)
{
Repeater repeater1 = (Repeater)i.FindControl("Repeater1");
Label articleLabel = (Label)i.FindControl("ArticleLabel");
ArticleFinderWebService t = new ArticleFinderWebService();
repeater1.DataSource = t.FindArticle(articleLabel.Text);
repeater1.DataBind();
}
}
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference
Path="TrackFinderWebService.asmx" />
</Services>
</asp:ScriptManager>
<br />
<asp:Button ID="UpdateAllButton" runat="server" Text="Button"
OnClick="UpdateAllButton_Click" /><br />
<asp:Repeater ID="DummyData" runat="server">
<ItemTemplate>
<table>
<tr>
<td width="300"><asp:Label ID="ArticleLabel"
runat="server" Text='<%# Bind("Article") %>'></asp:Label></td>
</tr>
</table>
<asp:UpdatePanel ID="InnerUpdatePanel" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table>
<tr>
<td width="20">
<asp:CheckBox
</td>
<td width="250">
<asp:Label ID="lblArticle"
runat="server" Text='<%# Bind("Article") %>'></asp:Label><br />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger
ControlID="UpdateAllButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
</asp:Repeater>
Now this code works fine but I have a few questions:
1. Is this the right way to do it? I guess I get confused when I use
ServerSide events to execute AJAX calls.
2. Let's assume I want a few webservices to be called (each webservice
grabs information about the article but from different sources on the
internet. Would it be better to use one webservice to go out and
collect data from different locations, put it in a datatable then
return it to the repeater in the updatepanel OR add another webservice
method and add another updatepanel in the ItemTemplate then have each
UpdatePanel call a different webmethod? I was thinking the latter
approach since everything will happen at the same time, and if one
webservice finishes before the other, that data will be displayed on
the page right away instead of having to wait and gather all the data
then present it.
Any feedback would be greatly appreciated.
Thanks