单页的部分更新 [英] Partial update of single page

查看:72
本文介绍了单页的部分更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我点击提交按钮时,每次刷新时,我需要同时在另一个标签字段中获取文本区域的结果。我知道它可以通过计时器来完成。但我不知道如何为我的代码实现这个概念。任何人都可以帮我解决这个问题。



点击我的提交按钮后,在我的按钮下方,lblCurrentPageURL应显示每个参考的数据(URL) 。

同时lbloutput1应该在完整的推荐或整个帖子完成后显示一次结果。

以下是我的代码:

C#

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#

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:



ASPX:

<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>

推荐答案

你可以使用更新面板来做到这一点,但我不建议这样做。



另一种更好的方法是调用Web服务,从Web方法保存数据,然后使用JavaScript设置标签内容。如果您决定继续使用这种方法,那么您必须在页面加载时也从后面的代码设置标签,以保持应用程序的一致性。



PS:我没有给出任何代码片段,你应该自己尝试一下以便更好地理解,如果你需要任何帮助,请参考以下关于.Net web services和web api的链接。



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



http://www.asp.net/web-api [ ^ ]
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[^]


这篇关于单页的部分更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆