Shortcuts

how to call aspx's function within ascx code?

Hi , I wrote a user control mycontrol.ascx, there is a button-A in mycontrol.ascx, then I use mycontrol.ascx in main.aspx, the main.aspx have a TextBox-T and a public function-F, now, when I click buton-A in mycontrol.ascx, how can I change the TextBox-T.Text
on Main.aspx, and how can I call the function-F on Main.aspx? --Ben

Re: how to call aspx's function within ascx code?

This is easier than you think. create an event in the code-behind of your ASCX.
public event EventHandler ButtonClick; then trap the click event of your button within the ASCX itself and raise your custom event.
protected void ButtonA_Click(object sender, EventArgs) { if(ButtonClick != null) ButtonClick(this, new EventArgs); }
Next, on your ASPX page, make sure you've declared the ASCX in the code-behind. Unfortunately this is not like WebControls where the declaration is automatically inserted for you. Remember this is done at the class level. protected MyControl ucMyControl;
// assuming you named it "ucMyControl" In VB: Protected WithEvents ucMyControl As MyControl
You then have to wire your event (you can do it in the Page_Load): ucMyControl.ButtonClick += new EventHandler(ucMyControl_ButtonClick); In VB: AddHandler ucMyControl.ButtonClick, AddressOf ucMyControl_ButtonClick
Then finally, create the method: protected void ucMyControl_ButtonClick(object sender, EventArgs e) { // This is where you can make whatever changes you want to your page. }
I hope this helps - good luck. Miguel Castro www.dotnetdude.com