Postbacks in User Controls

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

(Second Try)

Greetings,

I have an asp.net web application that utilizes a User Control at the top of
the page.

My User Control contains a Server Control menu which will require postbacks.

I currently cannot get this to happen, but I know the functionality is
there. Can anybody offer me some advice or point me in the right direction
to get my postbacks working in User Controls?

My codebehind is in vb.net.

Thank you kindly for your help,

-Dave
 
What do you mean when you say postbacks do not occur? Did you try to put
If(IsPostback) in your Page_Load of either web page or user control?
 
Kumar,

Thanks for the response. To keep an example simple, say I have a User
Control with a button and a label in it. When the button is clicked, the
label's text changes to "The button has been clicked." This works fine in a
page, but when it is in a user control, the postback occurs, but the text in
the label does not change.

-Dave
 
How you are trying to change the label's text in response to a button click
in the user control? Where did you put the code. Are you trying to change
the text of the correct url? Also did you enable the viewstate for the label
control and its parent, which is the userControl.?
 
Kumar,

Yes, the viewstates are all enabled (the controls in the User Control as
well as the User Control itself).

The button that is in the user control fires this event:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Label1.Text = "The button has been clicked"
End Sub

That sub is stored in the vb codebehind of the user control
(template.ascx.vb)
My main asp.net page (that uses the User Control) is simply default.aspx.
When I run default.aspx and click on that button (the button that is in the
user control), the Label1.Text does not change.

Hopefully this should give you a good understanding of what my problem is.
Please let me know if I can help you understand my problem any further.
 
Dave said:
I have an asp.net web application that utilizes a User Control at the top of
the page.

My User Control contains a Server Control menu which will require postbacks.

Take a look at the HTML that's getting generated. I'm not certain,
but I'd bet that the __DoPostBack script is only set up to handle a
single form per page.

If so, you'll either need to stick the User Control inside of the main
form wherever it is used, or handle postbacks from it by hand.
Remember, at the end of the day, it's still just CGI programming. If
ASP.NET won't do something for you, there's nothing to stop you from
doing it yourself.

Good luck!
Jason

http://www.expatsoftware.com/
 
Back
Top