如何处理Web用户控件中控件的事件 [英] how to handle event of the controls in web user control

查看:149
本文介绍了如何处理Web用户控件中控件的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I created a web user control which contains a dropDownList control.

ddlPatients.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ddlPatients.ascx.cs" Inherits="Admin_User_control_ddlPatients" %>

<asp:DropDownList ID="ddlCallsByPatient" runat="server" AutoPostBack="True" />



ddlPatients.ascx.cs

if (!Page.IsPostBack)

     BindDropDownLists();

And Drag And Drop it to aspx page.

Now I want to fire OnSelectedIndexChanged event to get the selected value of that dropDownList control in code behind.

推荐答案

在您的Web用户控件类中define event
in your web user control class define event
public event EventHandler SelectionChanged_UserControl;
//use OnSelectionChanged event of dropDownList 

void Selection_Change(Object sender, EventArgs e) 
      {

      SelectionChanged_UserControl(sender,e);

      }

//you will get SelectionChanged_UserControl event where you use web control 
//this event will fire when selection of dropDownList changed 


它是一个简单的解决方案

首先,在用户控件中,在Page_Load()方法上方创建一个委托

its a simple solution

First in user control create a delegate above Page_Load() method

public delegate void OnSelectedIndexchanged();
public event OnSelectedindexchanged Setactionname;



然后在下拉列表中选择索引更改,然后添加以下行



then in your dropdown selected index change add following line

if (Setactionname!= null)
                Setactionname();


然后转到您的ASPX页面并


then go to your ASPX page and

UsercontrolName.Setactionname+= this.Mehtodnameonlocalpage;



在页面后面的aspx代码中创建一个函数,然后像
一样做你需要做的事情



create a function in your aspx code behind page and do what u need to do like

private void SetSelectedActor()
    {

}


这篇关于如何处理Web用户控件中控件的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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