문제

So in ASP.NET I would simply do this:

    <asp:ListBox OnSelectedIndexChanged="UpdateModels" runat="server" > </asp:ListBox>

But my listbox is inside an .ascx file. which is registered and included in my actual webpage massupdate.aspx like this

<%@ Register TagPrefix="mass" TagName="make" Src="~/DynamicData/Make.ascx" %>
<mass:make id="makeControl" runat="server"/>

and in my make.ascx.cs I have this

   public ListBox getlistbox()
    {

        return DropDownList1;

    }

So I have access to the original listbox, but I don't know how to replicate the first code snippet in C# in my codebehind for mass.update.aspx .

도움이 되었습니까?

해결책

First of all, the event registered in the ascx should fire even though it is registered as a control onto the page. Events should bubble up (or maybe down?) through all of the controls on a page, that's part of the "magic" of webforms.

Secondly, if you do need to set an event handler in code, you can either google "add event handler .NET control" or you can type something similar below and Visual Studio intellisense should auto complete it for you after you type the "+=" and you can take it from there.

makeControl.getlistbox().OnSelectedIndexChanged += this.Index_Changed

void Index_Changed(Object sender, EventArgs e) {
    // whatever you need to do on the event
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top