ASP.NET基础代码备忘

时间:2021-09-26 01:27:33

使用ASP.NET原生的__doPostBack方法触发asp:Button

//javaScript部分
__doPostBack('<%=btnAmountDivided.UniqueID %>','');
<asp:Button ID="btnAmountDivided" runat="server" Style="display:none;" OnClick="btnDeptAmount_Click"></asp:Button>
protected void btnDeptAmount_Click(object sender, EventArgs e)
{
//Response.Write("A");
}

服务端控件的onclientClick()用法

OnClientClick="return confirm('确定要重置密码?');" 

onclientClick = "Xxx(); return false;" 就肯定不在执行doPostBack的Onclick=""
或者: onclientClick = "return Xxx(); " 在javaScript Xxx()方法定义中定义return false; 也肯定不在执行doPostBack的Onclick="", 如果return true, 会执行 doPostBack的Onclick="";

属性基于ViewState的属性

public CorpInfoEntity CorpInfoEntity{
set{
ViewState["CorpInfoEntity"] = value;
}
get
{
return ViewState["CorpInfoEntity"] as CorpInfoEntity;
}
}