給自定義Web控件添加事件(前后臺(tái)代碼)
<script src="js/Jquery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
function Register() {
if ($('#myRegister1_txtUserName').val() == '') {
$('#spanUserName').text('請(qǐng)輸入用戶名');
return false;
}
if ($('#myRegister1_txtPwd').val() == '') {
$('#spanPwd').text('請(qǐng)輸入密碼');
return false;
}
if ($('#myRegister1_txtPwd1').val() == '') {
$('#spanPwd1').text('請(qǐng)輸入密碼');
return false;
}
if ($('#myRegister1_txtPwd1').val() != $('#myRegister1_txtPwd').val()) {
$('#spanPwd1').text('兩次密碼要一致');
return false;
}
if ($('#myRegister1_txtEmail').val() == '') {
$('#spanEmail').text('請(qǐng)輸入郵箱');
return false;
}
return true;
}
</script>
<table>
<tr>
<td>用戶名:</td>
<td>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox></td>
<td><span id="spanUserName"></span></td>
</tr>
<tr>
<td>密碼:</td>
<td>
<asp:TextBox ID="txtPwd" runat="server"></asp:TextBox></td>
<td><span id="spanPwd"></span></td>
</tr>
<tr>
<td>確認(rèn)密碼:</td>
<td>
<asp:TextBox ID="txtPwd1" runat="server"></asp:TextBox></td>
<td><span id="spanPwd1"></span></td>
</tr>
<tr>
<td>郵箱:</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></td>
<td><span id="spanEamil"></span></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnRegister" runat="server" Text="注冊(cè)"
onclick="btnRegister_Click" OnClientClick="return Register()" /></td>
<td>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
------------myRegister1.ascx后臺(tái)代碼------------
public partial class myRegister : System.Web.UI.UserControl
{
public event MyRegeitserDelegate On_MyRegister;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnRegister_Click(object sender, EventArgs e)
{
if (On_MyRegister != null)
{
MyRegister.userName=txtUserName.Text;
MyRegister.pwd=txtPwd.Text;
MyRegister.email = txtEmail.Text;
On_MyRegister();
if (MyRegister.isBool == true)
{
Label1.Text = "注冊(cè)成功";
}
else
{ Label1.Text = "注冊(cè)失敗"; }
}
}
}
public class MyRegister
{
public static string userName { set; get; }
public static string pwd { set; get; }
public static string email { set; get; }
public static bool isBool { set; get; }
}
public delegate void MyRegeitserDelegate();
---------WebForm事件無(wú)參.aspx前臺(tái)代碼--------------
<uc1:myRegister ID="myRegister1" runat="server" />
---------WebForm事件無(wú)參.aspx后臺(tái)代碼---------------
public partial class WebForm事件無(wú)參 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.myRegister1.On_MyRegister += new MyRegeitserDelegate(myRegister1_On_MyRegister);
}
void myRegister1_On_MyRegister()
{
MyRegister.isBool = writer(MyRegister.userName, MyRegister.pwd, MyRegister.email);
}
private bool writer(string userName, string pwd, string email)
{
using (Stream stream = File.Open(@"E:\new.txt", FileMode.Append, FileAccess.Write))
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.WriteLine("用戶名:{0},密碼:{1},郵箱:{2}",userName,pwd,email);
}
}
return true;
}
}
相關(guān)文章
ASP.NET中RadioButtonList綁定后臺(tái)數(shù)據(jù)后觸發(fā)點(diǎn)擊事件
這篇文章主要介紹了ASP.NET中RadioButtonList綁定后臺(tái)數(shù)據(jù)后觸發(fā)點(diǎn)擊事件的相關(guān)資料,感興趣的小伙伴們可以參考一下2016-05-05ASP.NET GridView中加入RadioButton不能單選的解決方案
這篇文章主要介紹了ASP.NET GridView中加入RadioButton不能單選的解決方案,希望大家閱讀完本文有所收獲。2015-09-09ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后臺(tái)管理系統(tǒng)之前端頁(yè)面框架構(gòu)建源碼分享
這篇文章主要為大家分享了ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后臺(tái)管理系統(tǒng)之easyui前端頁(yè)面框架構(gòu)建源碼,感興趣的小伙伴們可以參考一下2016-07-07asp.net DataTable相關(guān)操作集錦(篩選,取前N條數(shù)據(jù),去重復(fù)行,獲取指定列數(shù)據(jù)等)
這篇文章主要介紹了asp.net DataTable相關(guān)操作,包括篩選,取前N條數(shù)據(jù),去重復(fù)行,獲取指定列數(shù)據(jù)等.基本涵蓋了DataTable的常見操作技巧,需要的朋友可以參考下2016-06-06asp.net Http異常eurl.axd出錯(cuò)信息解決方法
在IIS6中同時(shí)啟用了ASP.NET 2.0 和 ASP.NET 4.0 后,網(wǎng)站程序可能會(huì)出現(xiàn)如下錯(cuò)誤:“ System.Web.HttpException: Path ‘//eurl.axd/‘ was not found. ”2011-08-08AspNet Core上實(shí)現(xiàn)web定時(shí)任務(wù)實(shí)例
在本篇文章里小編給大家分享了關(guān)于AspNet Core上實(shí)現(xiàn)web定時(shí)任務(wù)的實(shí)例內(nèi)容,有興趣的朋友們學(xué)習(xí)參考下。2019-02-02