开发者

ASP.NET refresh part of web page while other web-service returns its call

开发者 https://www.devze.com 2023-03-29 01:43 出处:网络
WebPage.aspx <asp:Button ID=\"Button1\" runat=\"server\" Text=\"Submit\" onclick=\"Button1_Click\" />

WebPage.aspx

<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />

<asp:Timer ID="Timer1" runat="server" Interval="1000" 
    OnTick="StatusTimer_Tick" Enabled="False" />

<asp:ScriptManager ID="ScriptManager1" runat="server" />

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Label ID="Label1"></asp:Label>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1"/>
    </Triggers>
</asp:UpdatePanel>

<asp:UpdatePanel ID="UpdatePanel2" runat="server"&开发者_如何学运维gt;
    <ContentTemplate>
        <asp:Label ID="Label2"></asp:Label>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Button1" Event="Click"/>
    </Triggers>
</asp:UpdatePanel>

WebPage.aspx.cs

protected void Timer1_Tick(object sender, EventArgs e)
{
    Label1.Text = "Refreshed at : " + DateTime.Now.ToLongTimeString();
}

protected void Button1_Click(object sender, EventArgs e)
{
    Timer1.Enabled = true;

    //Call some web-service
    XMLComparisonService.Service1SoapClient oService = new XMLComparisonService.Service1SoapClient();
    oService.XMLComparison();
}
  1. So Button1_Click enables Timer1.
  2. Label1 in UpdatePanel1 should get refreshed every 1 second! (with Label1 printing the current time)
  3. Button1_Click also calls the web-service method "XMLComparison"

But Label1 doesnt refresh after the web-service method "XMLComparison" gets called... Is anything wrong with my approach?

Regards -Parag


It looks like you are calling a webservice, but not waiting for a response before updating the page.

Here is an example

http://www.codeproject.com/KB/webservices/WebServiceConsumer.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消