谢楼上的, 80分归你了,晚上定结!不过我还想问问有没有其他方法,如通过事件的参数EventArgs??
此问分数另计!
此问分数另计!
解决方案 »
- MSChart 画曲线图
- select 查询语句参数化后SqlDataReader读取不到数据啊
- 能不能写得和路径无关, transparent url(../images/f4.gif) repeat scroll 0 0
- 数据库里面 怎么打印一列中的全部行?
- asp.net 数据库更新问题
- 如何处理xml文件
- 跪求ASP固定代码转换(详见文章)
- 新手上路,请教asp.net关于实现多文件上传问题??
- 用ASP.NET网页嵌入PDF怎么隐藏工具栏?
- 如果使得在编辑datagrid中的某一行时,其中的某个字段变为下拉式菜单,并提供选择?
- 询问OleDb和SqlClient对sql数据库操作的性能比较
- 快乐王子,我的VS.NET调试也出问题了,按f5的时候就报错
{
//....
}
aspx 页中可以建立这个类的实例吗?
public class MyControl : Control, IPostBackEventHandler
{
// Create an integer property that is displayed when
// the page that contains this control is requested
// and save it to the control's ViewState property.
public int Number
{
get
{
if ( ViewState["Number"] !=null )
return (int) ViewState["Number"];
return 50;
} set
{
ViewState["Number"] = value;
}
} // Implement the RaisePostBackEvent method from the
// IPostBackEventHandler interface. If 'inc' is passed
// to this method, it increases the Number property by one.
// If 'dec' is passed to this method, it decreases the
// Number property by one.
public void RaisePostBackEvent(string eventArgument)
{
if ( eventArgument == "inc" )
Number = Number + 1; if ( eventArgument == "dec" )
Number = Number - 1;
}
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
protected override void Render(HtmlTextWriter writer)
{
// Converts the Number property to a string and
// writes it to the containing page.
writer.Write("The Number is " + Number.ToString() + " (" ); // Uses the GetPostBackEventReference method to pass
// 'inc' to the RaisePostBackEvent method when the link
// this code creates is clicked.
writer.Write("<a href=\"javascript:" + Page.GetPostBackEventReference(this,"inc") + "\">Increase Number</a>"); writer.Write(" or "); // Uses the GetPostBackEventReference method to pass
// 'dec' to the RaisePostBackEvent method when the link
// this code creates is clicked.
writer.Write("<a href=\"javascript:" + Page.GetPostBackEventReference(this,"dec") + "\">Decrease Number</a>");
}
}
<a href="javascript:__doPostBack('ctl10','inc')">Increase Number</a>when the post is submitted, asp.net will get "ctl10" from Request.Form["__EVENTTARGET"], then it will check if ctl10 implements IPostBackEventHandler, if it is, it will call your control's RaisePostBackEvent('inc')