Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Rebind on a .ascx control event

Posted on 2010-11-19
5
Medium Priority
?
968 Views
Last Modified: 2012-05-10
I have a .aspx page with a ListView control on it. It also has a .ascx control. In the .ascx  the user fills out various search criteria and clicks a button. How do I rebind the list view control on the .aspx page when a button is clicked from the .ascx ? If anyone can point me in the right direction on this it would be greatly appreciated.

Just as an FYI it wasn't my idea to design the search this way....

0
Comment
Question by:jazzcatone
  • 3
5 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 668 total points
ID: 34176742
one way is to create an event in your user control that triggers when your button onclick fires.
http://asp.net-tutorials.com/user-controls/events/
http://codebetter.com/blogs/brendan.tompkins/archive/2004/10/06/Easily-Raise-Events-From-ASP.NET-ASCX-User-Controls.aspx

then on the event handler on your page, programmatically bind the listview to whatever data is required.
0
 
LVL 4

Assisted Solution

by:Andre412
Andre412 earned 1332 total points
ID: 34176865
easy

in your control at the top

Event evCallDataBind()

in the control subroutine that you wish to fire a rebind on the listview control at the end just before the end sub of the last thing you want to do

RaiseEvent evCallDataBind()

now in your listview

We have 3 things
1. the subroutine that will be doing the rebind "Rebind"
2. a find control function that will sniff out your child control ctlChild in the listview, "FindControl"
3. a call to this subroutine in the load

and herer we are
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       
        're attach the events to the controls
        For Each objControl As Control In ListView.Controls
            FindControl(objControl)
        Next
    End Sub

    Sub FindControl(ByVal ctl As Control)
        For Each ctrlItem As Control In ctl.Controls
            If Not ctrlItem Is Nothing AndAlso TypeOf ctrlItem Is ctlChild Then
                AddHandler CType(ctrlItem, ctlChild).evCallDataBind, AddressOf Me.Rebind
            End If
            If ctrlItem.HasControls Then FindControl(ctrlItem)
            'Response.Write(ctrlItem.GetType.ToString & "<br />")
        Next
    End Sub
    
    Sub Rebind()
        lnqEnquiries.DataBind()
        GdEnquiries.DataBind()
    End Sub

Open in new window

0
 
LVL 4

Expert Comment

by:Andre412
ID: 34176888
oops didnt mean to post without explaining

ok so on each load we tie the rountine "Rebind" to the controls event call, thus the control is telling the form to fire Rebind when you raise the event from the control.

Sadly the handler needs to be attached on every load, but the speed is pretty quick so there is no impact on performance

hope this helps, any probs let me know
0
 
LVL 4

Assisted Solution

by:Andre412
Andre412 earned 1332 total points
ID: 34189504
hi jazz have you managed to solve this yet ?
0
 

Author Closing Comment

by:jazzcatone
ID: 34207953
yep ...Thanks much...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question