Friday, October 12, 2012

ASP.NET : Test Async on ASP.NET 4.5 ** await new WebClient().DownloadStringTaskAsync(url)

ASP.NET : Test Async on ASP.NET 4.5

Hello , This is a simple way to read other website to display or get some html text data.
i seem like jQuery.load("website") but it manage by ASP.NET engine.
Before use Async we must set Async="true" on ' <@Page Async="true" '
2 Step Below include sourcecode again

Before Click Test Button.

After Click Test Button, Text data will show you in Panel

Step 1 : Create button for fire event and Panel for disply data.

        <asp:Button ID="btntest" runat="server" Text="Test" OnClick="btntest_Click" />
        <asp:Panel ID="pnlTest" runat="server" GroupingText="testData">
            <asp:Label ID="lbltest" runat="server"></asp:Label>

Step 2 : Create Event and method.

        public async void TestAsync()
            string url = "";
            string content = await new WebClient().DownloadStringTaskAsync(url);
            lbltest.Text = content;

        protected void btntest_Click(object sender, EventArgs e)
Enjoy ASP.NET Zomdev.

No comments:

Post a Comment