Normally with VB and C# your class is inherited from the generated page class and has access to all the members of that class, which includes controls, etc. However, with Python, no inheritance is taking place. A class, called ScriptPage, is instantiated
directly and injected into what would normally be page methods like Page_Init, Page_Load, etc. Therefore, my button event handler is not part of any class and has no clue about the label.
Rather than using a global variable, however, we do have access to the sender object ( of type button in this case ), which does expose a Page property that does give us access to the ScriptPage. We will set the text of the label that way:
Dave Hayden
Member
26 Points
19 Posts
Re: Page_Init() and Programmatically Setting Click Handler
Dec 16, 2006 01:49 AM|LINK
I think you're right.
I spent the better part of a few hours learning a little about Python and reading this whitepaper:
http://www.asp.net/ironpython/WhitePaper.aspx?tabid=62
Normally with VB and C# your class is inherited from the generated page class and has access to all the members of that class, which includes controls, etc. However, with Python, no inheritance is taking place. A class, called ScriptPage, is instantiated directly and injected into what would normally be page methods like Page_Init, Page_Load, etc. Therefore, my button event handler is not part of any class and has no clue about the label.
Rather than using a global variable, however, we do have access to the sender object ( of type button in this case ), which does expose a Page property that does give us access to the ScriptPage. We will set the text of the label that way:
def Page_Init():
Button1.Click += Button1_Click
def Button1_Click(sender, args):
sender.Page.Label1.Text = "button1"
I appreciate the comments scotts as it got me in the right direction.
Pretty cool.
Regards,
Dave