asp.net html button,ASP.NET/HTML: HTML button's onClick property inside ASP.NET (.cs)

问题

I just wanna find out if there's a way to put my onClick event inside .cs:

where Login_Click() should be inside .cs:

protected void btnLogin_Click(object sender, EventArgs e)

{

// do something

}

Please do take note that I will not use ASP.NET button here, and that I will not put my Login_Click() event inside .html/.aspx so I can't 'expose' my codes. Any suggestions?

回答1:

You can do that on any server control and this button is made a server control by defining "runat=server". The problem is probably in your definition of the event:

You don't need "();" there...

Apart from that can you explain why you don't use the here because I don't really see a problem with that...

回答2:

You'll want to use the onServerClick. There's an example of how to do that on MSDN:

Click me!

protected void Button1_OnClick(object Source, EventArgs e) {

// secret codes go here

}

回答3:

btnLogin.Click += new EventHandler( btnLogin_Click );

will assign the btnLogin_Click event handler to the button's Click event.

however, I would point out that assigning a handler in the markup of the aspx page does not "expose your codes", as the HTML rendered down to the client doesn't have any of that information in it.

回答4:

I know it's late but i lost so much time on this problem. I was setting InnerHtml of a div with buttons. You need to add type="submit" to your button if you want it to work.

回答5:

It's late but for someone out there: Apply UseSubmitBehavior="False". Example

来源:https://stackoverflow.com/questions/3167246/asp-net-html-html-buttons-onclick-property-inside-asp-net-cs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值