求解一个.net控件里面的属性问题
比如,我在页面放一个textbox和一个button,然后页面加载并且不是回传页面的时候我给textbox赋值“222”,那么我点button,textbox的值始终是“...
比如,我在页面放一个textbox和一个button,然后页面加载并且不是回传页面的时候我给textbox赋值“222”,那么我点button,textbox的值始终是“222”。理论上说重新加载页面,textbox的属性text会初始化为空,为什么他没有初始化,是用的静态属性吗??
展开
5个回答
展开全部
你说的重新加载页面,是指在地址栏输入url,按回车那种(即get,而不是post)
你点击button,相当于进行了Post提交,
在Asp.net中,Textbox控件会自动维持状态,也就是相当于它自己去获取Request.Form["TexbboxId"],并对自己的Text赋值
你自己的控件这个需要你去维持状态,可以参考:http://www.cnblogs.com/ASPNET2008/archive/2008/12/11/1158486.html
你点击button,相当于进行了Post提交,
在Asp.net中,Textbox控件会自动维持状态,也就是相当于它自己去获取Request.Form["TexbboxId"],并对自己的Text赋值
你自己的控件这个需要你去维持状态,可以参考:http://www.cnblogs.com/ASPNET2008/archive/2008/12/11/1158486.html
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你是否设置了button的属性,autopostback=true;这样你点button时,textbox里的值就会为空
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
重新加载页面就是刷新网页 textbox文本是不会清空的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Excel.Application excel = new Excel.Application(); if (excel == null) { //MessageBox.Show("can't create file"); return; } Excel.Workbooks workbooks = excel.Workbooks; object missing = System.Reflection.Missing.Value; Excel.Workbook workbook; string str = @"E:\tmp\11.xls"; workbook = workbooks._Open(str, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets[1]; //Excel.Worksheet worksheet2 = (Excel.Worksheet)workbook.Worksheets[2]; excel.Application.DisplayAlerts = false;
//worksheet.Cells[1, 1] = null; //Excel.Range range; //range = worksheet2.get_Range(worksheet2.Cells[1, 1], worksheet2.Cells[3, 8]); //range.Copy((Excel.Range)worksheet.Cells[1, 1]); //range = (Excel.Range)worksheet.Cells[1, 1];
//range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlContinuous; //range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlLineStyle.xlContinuous; //range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlLineStyle.xlContinuous; //range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlLineStyle.xlContinuous;
//range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; //range.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;
//range.Font.Size = 20; Dictionary<string, string> redmineDic = new Dictionary<string, string>(); Excel.Range range2; range2 = worksheet.UsedRange; int rcount = 0; string allstring = null; for (rcount = 1; rcount <= range2.Rows.Count; rcount++) { try { if (redmineDic.ContainsKey((range2.Cells[rcount, 3] as Excel.Range).Text.ToString().Trim())) { //worksheet.Cells[rcount, 3] = null; Console.WriteLine("已删除第:" + rcount.ToString().PadRight(10) + "Redmine:" + (range2.Cells[rcount, 3] as Excel.Range).Text.ToString()); range2 = (Excel.Range)worksheet.Rows[rcount, missing]; range2.Delete(Excel.XlDeleteShiftDirection.xlShiftUp); range2 = worksheet.UsedRange; // rcount--; } else { redmineDic.Add((range2.Cells[rcount, 3] as Excel.Range).Text.ToString().Trim(), ""); } range2 = worksheet.UsedRange; } catch (Exception ex) { continue; }
} try { workbook.Saved = true; workbook.SaveCopyAs(@"E:\tmp\22.xls"); fileSaved = true; } catch (Exception ex) { fileSaved = false; // MessageBox.Show("error"); } finally { Console.Read(); workbooks.Close(); excel.Quit(); GC.Collect(); }
//worksheet.Cells[1, 1] = null; //Excel.Range range; //range = worksheet2.get_Range(worksheet2.Cells[1, 1], worksheet2.Cells[3, 8]); //range.Copy((Excel.Range)worksheet.Cells[1, 1]); //range = (Excel.Range)worksheet.Cells[1, 1];
//range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlContinuous; //range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlLineStyle.xlContinuous; //range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlLineStyle.xlContinuous; //range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlLineStyle.xlContinuous;
//range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; //range.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;
//range.Font.Size = 20; Dictionary<string, string> redmineDic = new Dictionary<string, string>(); Excel.Range range2; range2 = worksheet.UsedRange; int rcount = 0; string allstring = null; for (rcount = 1; rcount <= range2.Rows.Count; rcount++) { try { if (redmineDic.ContainsKey((range2.Cells[rcount, 3] as Excel.Range).Text.ToString().Trim())) { //worksheet.Cells[rcount, 3] = null; Console.WriteLine("已删除第:" + rcount.ToString().PadRight(10) + "Redmine:" + (range2.Cells[rcount, 3] as Excel.Range).Text.ToString()); range2 = (Excel.Range)worksheet.Rows[rcount, missing]; range2.Delete(Excel.XlDeleteShiftDirection.xlShiftUp); range2 = worksheet.UsedRange; // rcount--; } else { redmineDic.Add((range2.Cells[rcount, 3] as Excel.Range).Text.ToString().Trim(), ""); } range2 = worksheet.UsedRange; } catch (Exception ex) { continue; }
} try { workbook.Saved = true; workbook.SaveCopyAs(@"E:\tmp\22.xls"); fileSaved = true; } catch (Exception ex) { fileSaved = false; // MessageBox.Show("error"); } finally { Console.Read(); workbooks.Close(); excel.Quit(); GC.Collect(); }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询