Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I need to get the results of my text area in another lable field simultaniously when it get's refresh for each time while I click the Submit button. I know that it can be done by timer. but I dont know how to implement that concept for my code. can anyone help me to come out of this issue.

once after clicking my Submit button ,below of my button, lblCurrentPageURL should display the data(URL) for each refershment.
same time lbloutput1 should display the result once after the full refershment or whole post back completed.
Below is my code :
C#
C#
public List<string> lstResults = new List<string>();
       public int counter = 1;
       public string strInputURL;
       public int count;
       protected void Page_Load(object sender, EventArgs e)       {
       }
       public void GetURL(string strGetURL, string strParentURL)
       {
           var getHtmlSource = new HtmlWeb();
           var document = new HtmlDocument();
           try
           {
               document = getHtmlSource.Load(strGetURL);
               var aTags = document.DocumentNode.SelectNodes("//a");
               if (aTags != null){
                   foreach (var aTag in aTags){
                       string strURLTmp;
                       strURLTmp = aTag.Attributes["href"].Value;
                       strURLTmp = GetAbsoluteURL(strURLTmp, strParentURL);
                       if (!CheckDuplicate(strURLTmp)){
                           lstResults.Add(strURLTmp);
                           outputurl1.Text += counter + ". " + strURLTmp + "\n";
                           counter++;

                           lblCurrentPageURL.Text = strURLTmp; // to get the running URl
                           //(here only I have to get my data's simultaniously.but dont know how to implement the timer concept here)


                           if (strURLTmp.Contains(new System.Uri(strInputURL).Host)){
                               GetURL(strURLTmp, strGetURL);
                           }
                       }
                   }
               }
           }
           catch (Exception e){
           }
       }
       protected void btnSubmit_Click(object sender, EventArgs e){
           strInputURL = txtInput1.Text;
           lstResults.Add(strInputURL);
           GetURL(strInputURL, strInputURL);
       }
       public bool CheckDuplicate(string strURL){
           if (lstResults.Any() && lstResults.Contains(strURL)){
               return true;}
           else {
               return false;}
       }

       public static string GetAbsoluteURL(string strRelativeURL, string strbaseURL){
           return new Uri(new Uri(strbaseURL), strRelativeURL).AbsoluteUri;
       }
       protected void Timer1_Tick(object sender, EventArgs e){
           //dont know how to get my data here
       }


ASPX:
XML
<form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            <asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="100">
            </asp:Timer>
        </div>

        <asp:Label ID="lblURL1" runat="server" Text="Enter the URL Here" />
        <asp:TextBox ID="txtInput1" runat="server" />
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
        <br />
        <asp:Label ID="Label1" runat="server">Result
                <asp:TextBox ID="outputurl1" TextMode="multiline" Columns="50" Rows="5" runat="server" />
        </asp:Label><asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Always">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
            <ContentTemplate>
                <asp:Label CssClass="" ID="lblCurrentPage" runat="server" Text="Current Page :" />
                <asp:Label CssClass="" ID="lblCurrentPageURL" runat="server" />
                <br />
            </ContentTemplate>
        </asp:UpdatePanel>
Posted

1 solution

You can use Update Panel to do that but I would not recommend that.

Another better approach is to call a web service, save your data from the web method and then set the label contents using JavaScript. If you decide to move forward with this approach then you have to set the label from the code behind also at the time of page load to maintain consistency in your application.

PS: I have not given any code snippet and you should try this on your own for better understanding, still if you need any help then refer to the following link about .Net web services and web api.

http://msdn.microsoft.com/en-us/library/t745kdsh%28v=vs.90%29.aspx[^]

http://www.asp.net/web-api[^]
 
Share this answer
 
v2
Comments
Member 11091243 26-Sep-14 2:39am    
Im using Update panal only. I could't get the solution using web service also. Can you explain clearly?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900