(vb.net) Handling user-control events

Y

Yossi

I created a web-project containg an .aspx file and a self-
made User-Control (.acsx file) - all in vb.net.
My aspx file contains a Submit button (which is not part
of the User-Control).

I dynamiclly create the User-Control (using
the "LoadControl" command) and add it to a Panel located
on my aspx file.

I would like to save the values of the User-Control's
form-fields - as a response to a click on the Submit
button of my aspx file.

What is the write way to do that (short code-sample would
be great) ?
Thanks in advance,
Yossi
 
J

John Saunders

Yossi said:
I created a web-project containg an .aspx file and a self-
made User-Control (.acsx file) - all in vb.net.
My aspx file contains a Submit button (which is not part
of the User-Control).

I dynamiclly create the User-Control (using
the "LoadControl" command) and add it to a Panel located
on my aspx file.

I would like to save the values of the User-Control's
form-fields - as a response to a click on the Submit
button of my aspx file.

What is the write way to do that (short code-sample would
be great) ?
Thanks in advance,

Expose the form fields as public properties of the user control:

public string FormField1
{
get {return txtFormField1.Text;}
}

public int FormField2
{
get {return int.Parse(txtFormField2.Text);}
}

You can then refer to them in you button's Click event handler:

private void Button_Click(object sender, EventArgs e)
{
// You can now refer to userControl.FormField1 and
userControl.FormField2
}
 
Y

Yossi

As far as I understand, you suggest handling form-fields
of the User-Control within the aspx class. It means (in
terms of design), that I expose the User-Control behaviour
to the parent aspx class. I would like, on the other end,
to handle the values of the User-Control's form-fields
values within the control. Is it possible ?

I would like to get the submit-button event in my aspx
class, but instead of handling the event (saving the User-
Control's form-fields values), pass the event to the User-
Control. The User-Control will then handle the event by
itself. This way, the User-Control is self-contained. It
encpsulate the way to draw the control and also to save
its data. How can I do that ?

Thanks for the help so far,
Yossi
 
Y

Yossi

That is what I was tring to do,

The problem is that after the submit operation, the form-
fields get prefixes (i.e. cl1:myUserControlFormField) and
sometimes their data is lost (in case of file-upload input
fields). That is what I saw any way (I think it happens
because I dynamically create the User-Control). Or, I may
have done something wrong. I do the follwing:
Upon Submit event (from the aspx file), I dynamically
recreate the User-Control and calls the public event of
the control in a similiar way to the one you explained.
Then, the behaviour mentioned above occurs.

Is there something diffrent I should do ?
Thanks,
Yossi

P.S. It is the middle of the night (now in Israel :)) so
I'm going to sleep and will read more answers (if any) in
the morning. Thanks again, Yossi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top