Catch result

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I created a custom control where I have a few textboxes and a button
(MyButton).
When the button is clicked the textboxes data are sent to a database.

In MyButton_Click function I have a variable named Done.
If everything is went well I set this variable to True. Otherwise I set
it to false.

I placed this custom control on my page.

How can I get the value of Done in my page?

Basically, I need, in my page, to take an action according to the value
of Done after the button in the custom control is pressed.

Thanks,
Miguel
 
Create a public property that will acess your local private variable

// say this was the intialization of the variable
private bool done = false;

//we would make a property like this.
public bool Done
{
get
{ return done; }
// and if you want to let the form set the done property as well,
include the set accessor
set
{ done = value; }
}
 
Hi,

Yes, I know that.

But in my page how can I detect when the button is pressed so I can I
check that value?

I think I am missing something here.

Thanks,
Miguel
 
Declare an event, which your control would raise. Handle that event in your
ASPX form.
I hope you know how to create events in C#.

Andrey.
 
Hi,

I have no idea how to create events in my custom control.
Could you point some links to documentation or maybe an example?

Thanks,
Miguel
 
In order to create event in your control, you should:

1. Create EventArgs class

public class CustomControlButtonPressedEventArgs
{
bool _success;
public CustomControlButtonPressedEventArgs(bool success)
{
_success = success;
}
public bool Success
{
get { return _success; }
}
}

2. Create delegate type (for event handlers)

public delegate void CustomControlButtonPressedEventHandler(object sender,
CustomControlButtonPressedEventArgs e);

3. Create event

public event CustomControlButtonPressedEventHandler
CustomControlButtonPressed;

4. Create OnEvent function for raising the event

protected virtual void
OnCustomControlButtonPressed(CustomControlButtonPressedEventArgs e)
{
// Check if there are any handlers attached
if (CustomControlButtonPressed != null) CustomControlButtonPressed(this,
e);
}

5. Call OnCustomControlButtonPressed function when your control's button is
actually pressed.

HTH,
Andrey.
 
Back
Top