使用Button控件进行回发

时间:2015-10-26 11:32:02

标签: c# asp.net

我是初学者是ASP.NET。我有一个小疑问。我已经编写了一个简单的代码来打印文本框中已选中单选按钮的文本。我还没有使用单选按钮的autopostback属性。代码如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace web
{
    public partial class SAMPLE : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
        }
        protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton1.Checked)
                 TextBox1.Text = RadioButton1.Text;
        }
        protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton2.Checked)
                 TextBox1.Text = RadioButton2.Text;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }        
    }
}

检查单选按钮,单选按钮中的文本不会打印在文本框中,而是在按下按钮后打印。 我的疑问是在回发期间(点击按钮)只有按钮控件事件处理程序中的内容被执行但是其他事件处理程序中的语句如何被执行?

1 个答案:

答案 0 :(得分:1)

原因是单选按钮更改事件为Cached Event。这些事件保存在视图状态中,以便在发生回发事件时进行处理。因此,在这种情况下,当您单击按钮回发时,将执行单选按钮更改事件的缓存事件,该事件将存储在视图状态中。

TextBox控件的

TextChanged事件,DropDownList控件的SelectedIndexChanged事件也是缓存事件的示例。

通过将控件的Postback Events属性设置为true,可以将缓存事件转换为AutoPostBack

相关问题