locked
Dynamically Adding Controls and Detecting Session Begin/End RRS feed

  • Question

  • User297359420 posted

    I'm currently playing with IronPython in ASP.NET.  I have a couple questions, the foremost being, is it possible to add a new control(s) to a page programmatically in the IronPython script?  Examples include the ability to add new ListItems to a DropDownList, or any type of WebControl to a Panel.

    Also, using the Global.py, it appears that it only catches the Application level events, is there anyway to capture Session level events, the Session_End event is of particular importance to me.
    Also, it appears there is no way to access the Application object in the Application_Begin event.  Is there anyway to do this, or am I stuck attempting to only do this once in the Application_BeginRequest event.

    I believe that it is possible to use C# to do handle these application/session events within the project if necessary, just checking for the sake of language uniformity.

    Thursday, September 27, 2007 9:38 AM

All replies

  • User1641955678 posted

    Yes, you should be able to add controls dynamically.  e.g. try something like this:

    def Page_Load(sender, e):
        l=System.Web.UI.WebControls.Label()
        l.Text = "Hello"
        form1.Controls.Add(l)

      

    In Application_Start(), you can at to the application using 'app=System.Web.HttpContext.Current.Application'.

    Unfortunately, Session_End is not currently supported.

    Hope this helps,
    David

    Thursday, September 27, 2007 4:20 PM
  • User297359420 posted

    Thanks, I'm not sure why it failed to add controls.  I'm still debugging my logic on that page, but eventually I was able to add the controls no problem to other pages.

    Thanks for the heads up on Application_Start() 

    Wednesday, October 3, 2007 2:52 PM