自定义控件的问题 控件c# 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <body> <form id="form1" runat="server"> <table width="800" height="25" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td>您的位置:<a href="CourseStudyRight.aspx">首页</a>>><a href="SPracticeList.aspx">在线练习</a>>>完成练习</td> <td align="center"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="1000"></asp:Timer> </ContentTemplate> </asp:UpdatePanel> </td> </tr> </table> <table width="800" align="center"> <tr> <td> <asp:Panel ID="Panel2" runat="server"> <uc1:UserPratice ID="UserPratice1" runat="server" /> </asp:Panel> </td> </tr> <tr> <td align="center"> <asp:Button ID="btnTiJiaoAll" OnClientClick="return Checksubmit();" runat="server" Text="全部提交" OnClick="btnTiJiaoAll_Click" CssClass="inputbuton" /> </td> </tr> </table> </form></body>只在这一处地方 用到了这个控件 public partial class UserPratice : System.Web.UI.UserControl{ CPracticePater paper = new CPracticePater(); string practiceid= ""; protected void Page_Init(object sender, EventArgs e) { ………………………………………… if(!ispostback) string practicePaperId = ""; } public void CreatePractice( …………) { this.practicePaperId = ………………; }} 但是这个practicePaperId我在该类的其他成员函数也是要用到的呀 现在我把practicePaperId设成static是可以解决问题 但是我不知道为什么这个控件会被多次实例化?或者说是为什么string practicePaperId = "";会被多次执行? 你在这条语句调试中断时,可以查看“调用堆栈”,可以看所有的调用入口、以及入口代码的环境变量值。你不贴出来,谁也不知道程序怎么调用它。另外你在问题中也没有说明“何处调用 CreatePractice 这个方法”。这在vs开发工具上需要使用“查找所有引用”来找到,而且要先贴出来,否则谁也不知道你何时调用它。设置 if(!ispostback) 没有意义。因为这个地方根本取不到“postback”状态,这个 if 判断永远都是 true。而且就算取到 postback状态,也是瞎拼凑的、不符合业务逻辑的。 public partial class UserPratice : System.Web.UI.UserControl{ CPracticePater paper = new CPracticePater(); string practiceid = ""; string practicePaperId = ""; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { tystk.Models.CUser cUser = (tystk.Models.CUser)Session["LoginUsr"]; if (cUser != null) { if (Request.Params["practiceId"] == null) { Response.Write("<script>alert('抱歉,读取试卷出错!');location.reload('SPracticeList.aspx');</script>"); return; } this.practiceid = Request.Params["practiceId"].ToString(); this.CreatePractice(cUser); //调用CreatPractice } else { ErrorLog("登陆超时!"); Response.Redirect("../LetMeIn.aspx"); } } } public void CreatePractice( ) { this.practicePaperId = ………………; } public void CheckPratice( ) { ............ = this.practicePaperId; }}这是详细 而且我现在发现 string practicePaperId = ""; 是一直不断地在初始化 当我进入首页 首页总不包含这个控件 我也没有进行任何操作 但是这条语句不停地在执行 设为断点以后 按一下F5马上就跳回到这条语句 从你贴的图,看不出你调试时中断在哪一行?!如果中断在你在问题中说的那一行赋值语句,那么堆栈顶层应该看到的是 xxxxxxxx.dll!UserParctice.CreatePractice() 行 25 这样的CreatePractice方法,而不是对象初始化方法。 从你贴的图,看不出你调试时中断在哪一行?!如果中断在你在问题中说的那一行赋值语句,那么堆栈顶层应该看到的是 xxxxxxxx.dll!UserParctice.CreatePractice() 行 25 这样的CreatePractice方法,而不是对象初始化方法。调用堆栈中还是显示这条 可以看出什么吗 单步执行2、3行,就会回到宿主的aspx里边去执行,你就知道是哪个页面在调用它了。 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StudentPractice.aspx.cs" Inherits="Webs.StudentPractice" %><%@ Register Src="App_Controls/UserPratice.ascx" TagName="UserPratice" TagPrefix="uc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>教学互进管理系统</title> <link href="../css/css.css" rel="stylesheet" type="text/css" /> <script type="text/JavaScript" src="../JS/frame.js"></script></head><body> <form id="form1" runat="server"> <table width="800" height="25" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td>您的位置:<a href="CourseStudyRight.aspx">首页</a>>><a href="SPracticeList.aspx">在线练习</a>>>完成练习</td> <td align="center"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="10000"></asp:Timer> </ContentTemplate> </asp:UpdatePanel> </td> </tr> </table> <table width="800" align="center"> <tr> <td> <asp:Panel ID="Panel2" runat="server"> <uc1:UserPratice ID="UserPratice1" runat="server" /> </asp:Panel> </td> </tr> <tr> <td align="center"> <asp:Button ID="btnTiJiaoAll" OnClientClick="return Checksubmit();" runat="server" Text="全部提交" OnClick="btnTiJiaoAll_Click" CssClass="inputbuton" /> </td> </tr> </table> </form></body></html>单步执行几次后 跳转到了这个aspx页面里 我发现了问题 这个aspx里有个timer1控件用来显示时分秒考试倒计时 当interval间隔为1秒的时候 timer1_tick和string practicePaperId = "";这个初始化是同步进行的 为了证明这一点 我把interval设为10秒 发现确实如此 是UserParctice.ascx随着timer控件一起刷新了吗 但是为什么呢 我并没有把UserPartice放到UpdatePanel里面去呀 上面Label1是用来显示倒计时文本的 Timer1是定时器 UserPratice1是自定义控件 嗯,我在csdn上没有太多耐心看大段的程序,要么是根据你的流程设计描述,要么就只能根据快速地(可能就是几秒钟的)阅读你的代码大概看一下。根据我的理解,你是不太理解 UpdataPanel 机制问题。实际上asp.net ajax根本不是真正轻量级的 ajax,因此它提交数据时仍然是在服务器端重建了整个aspx(这也就包括了内部包含的ascx)。真因为这样,asp.net ajax才可能真正正确处理所有的控件的状态数据,并且触发所有事件(包括不在UpdataPanel里边的控件的事件)。虽然你以为仅仅“局部刷新”了,其实asp.net是整个重建整个aspx控件的。基于这个原理,重新设计你的程序逻辑流程,避免数据处理错误。 轻量级的ajax,是“单页面”的客户端javascript真的去局部改变DOM对象内容,从而局部刷新的。而asp.net ajax是2003研发2005年发布的东西,那个时代的产物,它实际上回发到服务器端重建整个页面,只不过是“伪局部刷新”客户端页面,在服务器端没有半点“局部刷新”的功能的。 那么是否有必要放弃或少用asp.net ajax,改为用Javascript实现? 感觉asp.net自带的控件用起来不舒服 像您说的 如果要想了解这些控件的机制 应该通过什么或者说在哪里了解呢 相关书籍好像也没并没有提及 那么是否有必要放弃或少用asp.net ajax,改为用Javascript实现? 感觉asp.net自带的控件用起来不舒服 像您说的 如果要想了解这些控件的机制 应该通过什么或者说在哪里了解呢 相关书籍好像也没并没有提及 可以再回答一下吗 那么是否有必要放弃或少用asp.net ajax,改为用Javascript实现? 感觉asp.net自带的控件用起来不舒服 像您说的 如果要想了解这些控件的机制 应该通过什么或者说在哪里了解呢 相关书籍好像也没并没有提及 如何在类中使用Session web 数据维护程序 问各位高手个获取表单请求的问题 基于WBE打印国内研究现状 求 Web Service Software Factory ,可用下载地址, 请教图片新闻问题 怎么做一个有背景图并且可以动态设置上面文字的按钮 偶想用自己的电脑作服务器~~~有几个软/硬件问题想请教.. 在asp.net中读取客户端机子的ip? Design My First Web-之Link Button问题 弹出窗口 asp.net正则表达式求HTML title
<table width="800" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>您的位置:<a href="CourseStudyRight.aspx">首页</a>>><a href="SPracticeList.aspx">在线练习</a>>>完成练习</td>
<td align="center"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="1000"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
<table width="800" align="center">
<tr>
<td>
<asp:Panel ID="Panel2" runat="server">
<uc1:UserPratice ID="UserPratice1" runat="server" />
</asp:Panel>
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="btnTiJiaoAll"
OnClientClick="return Checksubmit();" runat="server" Text="全部提交"
OnClick="btnTiJiaoAll_Click" CssClass="inputbuton" />
</td>
</tr>
</table> </form>
</body>只在这一处地方 用到了这个控件
public partial class UserPratice : System.Web.UI.UserControl
{
CPracticePater paper = new CPracticePater();
string practiceid= "";
protected void Page_Init(object sender, EventArgs e)
{
…………………………………………
if(!ispostback)
string practicePaperId = "";
}
public void CreatePractice( …………)
{
this.practicePaperId = ………………;
}
}
但是这个practicePaperId我在该类的其他成员函数也是要用到的呀
string practicePaperId = "";会被多次执行?
{
CPracticePater paper = new CPracticePater();
string practiceid = "";
string practicePaperId = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
tystk.Models.CUser cUser = (tystk.Models.CUser)Session["LoginUsr"];
if (cUser != null)
{
if (Request.Params["practiceId"] == null)
{
Response.Write("<script>alert('抱歉,读取试卷出错!');location.reload('SPracticeList.aspx');</script>");
return;
}
this.practiceid = Request.Params["practiceId"].ToString();
this.CreatePractice(cUser); //调用CreatPractice
}
else
{
ErrorLog("登陆超时!");
Response.Redirect("../LetMeIn.aspx");
}
}
}
public void CreatePractice( )
{
this.practicePaperId = ………………;
}
public void CheckPratice( )
{
............ = this.practicePaperId;
}
}这是详细 而且我现在发现 string practicePaperId = ""; 是一直不断地在初始化 当我进入首页 首页总不包含这个控件 我也没有进行任何操作 但是这条语句不停地在执行 设为断点以后 按一下F5马上就跳回到这条语句
从你贴的图,看不出你调试时中断在哪一行?!如果中断在你在问题中说的那一行赋值语句,那么堆栈顶层应该看到的是 xxxxxxxx.dll!UserParctice.CreatePractice() 行 25 这样的CreatePractice方法,而不是对象初始化方法。
从你贴的图,看不出你调试时中断在哪一行?!如果中断在你在问题中说的那一行赋值语句,那么堆栈顶层应该看到的是 xxxxxxxx.dll!UserParctice.CreatePractice() 行 25 这样的CreatePractice方法,而不是对象初始化方法。
调用堆栈中还是显示这条 可以看出什么吗
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>教学互进管理系统</title>
<link href="../css/css.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="../JS/frame.js"></script>
</head>
<body> <form id="form1" runat="server">
<table width="800" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>您的位置:<a href="CourseStudyRight.aspx">首页</a>>><a href="SPracticeList.aspx">在线练习</a>>>完成练习</td>
<td align="center"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="10000"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
<table width="800" align="center">
<tr>
<td>
<asp:Panel ID="Panel2" runat="server">
<uc1:UserPratice ID="UserPratice1" runat="server" />
</asp:Panel>
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="btnTiJiaoAll"
OnClientClick="return Checksubmit();" runat="server" Text="全部提交"
OnClick="btnTiJiaoAll_Click" CssClass="inputbuton" />
</td>
</tr>
</table> </form>
</body>
</html>
单步执行几次后 跳转到了这个aspx页面里 我发现了问题 这个aspx里有个timer1控件用来显示时分秒考试倒计时
当interval间隔为1秒的时候 timer1_tick和string practicePaperId = "";这个初始化是同步进行的 为了证明这一点 我把interval设为10秒 发现确实如此 是UserParctice.ascx随着timer控件一起刷新了吗 但是为什么呢 我并没有把UserPartice放到UpdatePanel里面去呀
UserPratice1是自定义控件
嗯,我在csdn上没有太多耐心看大段的程序,要么是根据你的流程设计描述,要么就只能根据快速地(可能就是几秒钟的)阅读你的代码大概看一下。根据我的理解,你是不太理解 UpdataPanel 机制问题。实际上asp.net ajax根本不是真正轻量级的 ajax,因此它提交数据时仍然是在服务器端重建了整个aspx(这也就包括了内部包含的ascx)。真因为这样,asp.net ajax才可能真正正确处理所有的控件的状态数据,并且触发所有事件(包括不在UpdataPanel里边的控件的事件)。虽然你以为仅仅“局部刷新”了,其实asp.net是整个重建整个aspx控件的。基于这个原理,重新设计你的程序逻辑流程,避免数据处理错误。
那么是否有必要放弃或少用asp.net ajax,改为用Javascript实现? 感觉asp.net自带的控件用起来不舒服 像您说的 如果要想了解这些控件的机制 应该通过什么或者说在哪里了解呢 相关书籍好像也没并没有提及