2012-07-25 68 views
1

我有我的代码,并扩展版本 -加载javascript和速度问题

string CurrMonth = "Jan"; 
int rowId = 1; 
string MIMO = ""; 
double JanMITotal = 0.0; 
double JanMOTotal = 0.0; 
//continued all the way to December 

foreach (DataRow dr in dtMIMODetails.Rows) { //dtDetail has about 50 rows 
    HtmlTableRow rowDetails = new HtmlTableRow(); 
    MIMO = dtMIMODetails["MIMO".ToString(); 
    { 
    CurrMonth = "Jan"; 
    HtmlTableCell cell = new HtmlTableCell(); 
    cell.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#FFFF99"); 
    cell.Style.Add(HtmlTextWriterStyle.TextAlign, "center"); 

    TextBox tb = new TextBox(); 
    tb.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#FFFF99"); 
    tb.Style.Add(HtmlTextWriterStyle.TextAlign, "center"); 
    tb.Style.Add(HtmlTextWriterStyle.FontSize, "small"); 
    tb.Style.Add(HtmlTextWriterStyle.Width, "40px"); 
    tb.Style.Add(HtmlTextWriterStyle.Display, "None"); 
    tb.ID = "tb" + CurrMonth + "_" + MIMO + "_" + "_" + rowID; 
    tb.Text = drMIMODetails[CurrMonth].ToString(); 

    HtmlAnchor htmlanchor = new HtmlAnchor(); 
    htmlanchor.ID = "ha" + CurrMonth + "_" + MIMO + "_" + rowID; 
    htmlanchor.HRef = "#" + htmlanchor.ID; 
    htmlanchor.Title = "Click to change value"; //tooltip 
    htmlanchor.InnerText = drMIMODetails[CurrMonth].ToString(); 
    htmlanchor.Attributes.Add("onclick", "handleTextBox('" + CurrMonth + "', '" + MIMO + "', '" + rowID + "', 'Show')"); 

    tb.Attributes.Add("onkeyup", "updateMIMOTotals('" + CurrMonth + "', '" + MIMO + "', '" + recordID + "','" + rowID + "')"); 
    tb.Attributes.Add("onblur", "handleTextBox('" + CurrMonth + "', '" + MIMO + "', '" + rowID + "', 'Hide')"); 

    FilteredTextBoxExtender ftbe = new FilteredTextBoxExtender(); 
    ftbe.ID = "ftbe" + CurrMonth + "_" + MIMO + "_" + rowID; 
    ftbe.TargetControlID = tb.ID; 
    ftbe.FilterType = FilterTypes.Custom | FilterTypes.Numbers; 
    ftbe.ValidChars = "."; 

    cell.Controls.Add(tb); 
    cell.Controls.Add(ftbe); 
    cell.Controls.Add(htmlanchor); 
    rowDetails.Cells.Add(cell); 

    if (MIMO == MOVEINS) { 
     JanMITotal = JanMITotal + Convert.ToDouble(drMIMODetails[CurrMonth]); 
    } 
    else if (MIMO == MOVEOUTS) { 
     JanMOTotal = JanMOTotal + Convert.ToDouble(drMIMODetails[CurrMonth]); 
    } 
    } 

    rowId++; 
} 

这是重复了12个月。

此表单上还有其他值,当更改时会导致此循环再次运行,这很好。我需要重新加载值,结果是其他值更改的原因。

但做了其他更改并重新加载页面约4-5次后,我得到了可怕的“停止运行脚本?”错误。

有没有更好的方法?我有一个我使用的JavaScript文件,并且对jQuery稍微熟悉。

+0

'停止运行脚本'与C#代码无关。它完全是指JavaScript。 – mellamokb 2012-07-25 17:01:37

+0

发布JS代码... – Nik 2012-07-25 17:05:50

+0

但它没有运行脚本。我的onkeyup事件更新DOM中的其他元素并完成。我已经添加了断点以确保我不处于某种无限循环。 – duckmike 2012-07-25 17:07:38

回答

1

它发生在与单元相关的事件之一上:onkeyup,onblur或onclick。

1

停止运行脚本表示我怀疑有无限循环。如果你需要这方面的帮助,你应该发布你正在运行的客户端代码(JavaScript)。

+0

好吧,我处理了3个js事件 - onclick,onkeyup和onblur,用于每个文本框。我在javascript中添加了断点,并且没有任何无限循环。 – duckmike 2012-07-25 17:06:40