如何为输入类型=提交按钮编写代码 [英] How Do I Write Code Behind For Input Type=Submit Button

查看:97
本文介绍了如何为输入类型=提交按钮编写代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个提交类型的输入按钮,我想在点击输入按钮时运行一组特定的代码。我是我的输入按钮



Hi,

I have an input button of type submit and i want to make a particular set of code to run on clicking the input button.Below is my input button

<input type="submit" value="Submit me"  runat="server"  önclick="submited">





任何人都可以告诉我如何为这种类型的输入按钮编写代码。谢谢你。祝福你



can anyone tell me how to write code behind for this type of input button.Thank you in advance.god bless you

推荐答案

在输入标记中添加:

Add this in the input tag:
OnServerClick="submited"



然后在后面的代码中添加:


then in the code behind, add:

protected void submited(Object sender, EventArgs e)
{
    TextBox1.Text = "hello world";
}



运行它,它应该回发并用'hello world'填充textbox1


run it, it should post back and fill up the textbox1 with 'hello world'


在ASP中.NET若要将代码与提交按钮关联,则应使用ASP:BUTTON控件,如下例所示:



< asp:Button ID = saveButtonText ='保存'runat =服务器OnClick =saveButton_Click/>



然后在你的代码中你应该实现与上面按钮链接的方法:



In ASP.NET if you want to associate code behind with a submit button you should use ASP:BUTTON control like in the next example:

<asp:Button ID="saveButton" Text='Save' runat="server" OnClick="saveButton_Click"/>

Then in your code you should implement the method linked with the button above:

protected void saveButton_Click(object sender, EventArgs e)
{
 //....
}





请注意点击按钮的事件处理程序将在 Page_Load 事件后执行。


这篇关于如何为输入类型=提交按钮编写代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆