我想更新我的文本框控件在Asp.Net文本属性从循环内我已经尝试使用Ajax更新面板与计时器控件,但无法更新文本属性。我一直搜索这个自上周以来,但无法找到任何答案任何帮助,将higly赞赏通过循环更新文本框的文本属性
以下是详细:
这是我在这个代码按钮单击事件中,你可以看到我更新的
TxtContent.Text
在一个循环内文本是bei NG返回由称为
ReturnBodyText()
后来我分配文本视图状态,以便在计时器滴答事件中,我能回忆起的文字和更新文本框的文本属性,然后在计时器滴答事件分配一个用户定义的函数视图状态值到文本框。
protected void Button4_Click(object sender, EventArgs e)
{
ArrayList FilePath = (ArrayList)ViewState["ArrayList"];
int i = 0;
int b = 1;
foreach(string[] sr in FilePath)
{
string Month = sr[i];
string datewithzero;
datewithzero = String.Format("{0:00}", b);
string[] FilesArray = (string[])listfiles(Month, datewithzero).ToArray(typeof(string));
foreach (string FileNameWithExtension in FilesArray)
{
ListBox4.Items.Add(FileNameWithExtension);
TxtContent.Text = ReturnBodyText(Month, datewithzero, FileNameWithExtension);
ViewState["Content"] = TxtContent.Text;
Timer1.Enabled = true;
Timer1_Tick(ViewState["Content"], e);
}
i = i + 1;
b = b + 1;
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
TxtContent.Text =(string) ViewState["Content"];
TxtContent.DataBind();
}
我希望上面的描述将有助于理解我的问题
完整的aspx文件你们和后面的代码如下:
.aspx的代码:
<%@ Page Language =“C#”AutoEventWireup =“true”CodeFile =“Default.aspx.cs”Inherits =“_ Default”%>
<%@注册组件= “AjaxControlToolkit” 命名空间= “AjaxControlToolkit” 的TagPrefix = “ASP” %>
<asp:ListBox ID="ListBox1" runat="server" Height="509px" Width="59px"> </asp:ListBox> <asp:Button ID="Button2" runat="server" Height="26px" onclick="Button2_Click" Text="To be pressed first" Width="130px" /> <asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="To be pressed 2nd" Width="131px" Height="26px" /> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick" Enabled="False"> </asp:Timer> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:TextBox ID="TxtContent" runat="server" Height="508px" AutoPostBack="True" TextMode="MultiLine"></asp:TextBox> <asp:Button ID="Button5" runat="server" Height="26px" onclick="Button4_Click" Text="To be pressed Third" Width="122px" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> </asp:UpdatePanel> </div> </form>
- Codebehind:
using System; using System.Collections.Generic;使用System.Linq的 ; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;使用System.Net的 ;使用System.IO的 ;使用System.Collections的 ;
公共部分类_Default:FTP {
protected void Button2_Click(object sender, EventArgs e) { string[] array = (string[])listfiles().ToArray(typeof(string)); ViewState["FolderName"] = array; foreach (string FileName in array) { ListBox1.Items.Add(FileName); } } protected void Button3_Click(object sender, EventArgs e) { string[] arraylistbox2 = (string[])ViewState["FolderName"]; string[] arrays = new string[12]; ArrayList ListPath = new ArrayList(); int dateFolder; foreach (string FileName in arraylistbox2) { dateFolder = Convert.ToInt16(FileName); dateFolder = dateFolder - 1; ListPath.Add((string[])(listfiles(FileName).ToArray(typeof(string)))); } ViewState["ArrayList"] = ListPath; } protected void Button4_Click(object sender, EventArgs e) { ArrayList FilePath = (ArrayList)ViewState["ArrayList"]; int i = 0; int b = 1; foreach(string[] sr in FilePath) { string Month = sr[i]; string datewithzero; datewithzero = String.Format("{0:00}", b); string[] FilesArray = (string[])listfiles(Month, datewithzero).ToArray(typeof(string)); foreach (string FileNameWithExtension in FilesArray) { TxtContent.Text = ReturnBodyText(Month, datewithzero, FileNameWithExtension); ViewState["Content"] = TxtContent.Text; Timer1.Enabled = true; Timer1_Tick(ViewState["Content"], e); } i = i + 1; b = b + 1; } } protected void Timer1_Tick(object sender, EventArgs e) { TxtContent.Text =(string) ViewState["Content"]; TxtContent.DataBind(); }
你能确认你的定时工作?就像你在调试时你正在触发Timer1_Tick事件一样? – Bobby
如果可以,可以发布所有相关的代码吗?包括.aspx内容。那会让我们重现你的问题。尽管我尊重那些没有这个能够解决这个问题的人,但我不是其中之一。 – besamelsosu
@Bobby是我Timer1_Tick事件正在调试模式下命中断点 – user758528