This is a migrated thread and some comments may be shown as answers.

Rebind a RadGrid on User Control from another User Control???

6 Answers 207 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
long
Top achievements
Rank 1
long asked on 08 Oct 2010, 11:17 AM
I have just studied  RadControl for 1 week. So I have a lot of thing that I don't know. Sorry If my questions don't fit.

This is my problem:
How could you rebind a radgrid on a User Control from another User Control ?

I have an Content ASPX page( create from Master Page)  with two user controls pages. The first User Control Page is "Register Page", and the second UserControl Page is "Information Page". When I click Register Button on "Register Page" and Successfull , " Information Page" will rebind  RadGrid .

OK, I had Succeeded If Register and  RadGrid Information were on a ASPX page . But with this situation, I don't know how to do it . Thanks a lot !!!

6 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 08 Oct 2010, 12:59 PM
Hi long,

Please refer to the following help topic which elaborates on this matter.
I hope it helps.


Regards,
Maria Ilieva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
long
Top achievements
Rank 1
answered on 08 Oct 2010, 04:30 PM
OH, thanks, sorry , because have a lot of thing so I had passed this . I will read it and If I don't Understand, I hope you can help me. Thanks a lot!!!
0
long
Top achievements
Rank 1
answered on 11 Oct 2010, 04:31 AM
I had tried and I have some problem.
this is My Main.Master
<body>
    <form id="form1" runat="server">
    <div style="height: 174px; width: 668px">
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server"
            Skin="Default">
        </telerik:RadAjaxLoadingPanel>
     <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
         
        </asp:ContentPlaceHolder>
         
    </div>
    <div>
     
        <table width="100%" style="height: 297px">
        <tr>
        <td class="style1"><asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server"></asp:ContentPlaceHolder></td>
        <td class="style2">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder4" runat="server" />
   </td>
        </tr>
        </table>
         
    </div>
    <div>
    <asp:Panel ID="Panel1" runat="server">
    <asp:ContentPlaceHolder ID="ContentPlaceHolder3" runat="server">
     </asp:ContentPlaceHolder>
        </asp:Panel>
    </div>
    </form>
</body>
This is my Main.aspx
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <uc3:Calendar ID="Calendar1" runat="server" />
</asp:Content>
<asp:Content ID="Content3" runat="server"
    contentplaceholderid="ContentPlaceHolder2">
    
    </asp:Content>
<asp:Content ID="Content4" runat="server"
    contentplaceholderid="ContentPlaceHolder4">
    <uc1:Register ID="Register1" runat="server" />
    </asp:Content>
<asp:Content ID="Content5" runat="server"
    contentplaceholderid="ContentPlaceHolder3">
 
 
    <uc6:Database ID="Database1" runat="server" />
 
 
</asp:Content>
OK, I only use ContentPlaceHolder4 for Register.ascx  and ContentPlaceHolder3 for Database.ascx ( include RadGrid for Account information in Database ).
This is Main.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
        {
 
            //Load
            Page.Master.FindControl("ContentPlaceHolder4").Controls.Add(LoadControl("Register.ascx"));
            Page.Master.FindControl("ContentPlaceHolder4").Controls[1].ID = "Register1";
            //Ta muốn thiết lập ảnh hưởng khi nhấn buttonRegister trên Register.aspx
            //lên Database.aspx thông qua Panel1 thì ta cần thiết lập config của
            //RadAjaxManager
            Button AjaxButtonLoad = (Button)Page.Master.FindControl("ContentPlaceHolder4").FindControl("Register1").FindControl("bttRegister");
            //   Button AjaxButtonClear = (Button)Content("ContentPlaceHolder3").FindControl("UserControl1").FindControl("btnClear");
            //Get the manager and the panel from the MasterPage
            RadAjaxManager AjaxManager = (RadAjaxManager)Page.Master.FindControl("RadAjaxManager1");           
            Panel MyPanel = (Panel)Page.Master.FindControl("Panel1");
            RadAjaxLoadingPanel loadpanel = (RadAjaxLoadingPanel)Page.Master.FindControl("RadAjaxLoadingPanel1");
            //Add the necessary AJAX settings - buttons update the panel in order to load the second user control there
            AjaxManager.AjaxSettings.AddAjaxSetting(AjaxButtonLoad, MyPanel);
            //    AjaxManager.AjaxSettings.AddAjaxSetting(AjaxButtonClear, MyPanel, null);
        }
        protected override bool OnBubbleEvent(object source, System.EventArgs args)
        {
            CommandEventArgs commandArgs = args as CommandEventArgs;
            //determine whether to load the user control depending on bubbled button command
            if (commandArgs != null)
            {
                if (commandArgs.CommandName == "Load")
                {
                    Page.Master.FindControl("ContentPlaceHolder3").Controls.Add(LoadControl("Database.ascx"));
                    Page.Master.FindControl("ContentPlaceHolder3").Controls[1].ID = "Database1";
                }
                //else if (commandArgs.CommandName == "Clear")
                //{
                //    //do nothing. the control won't be loaded anyway
                //}
            }
            return base.OnBubbleEvent(source, args);
        }
I want to Add the necessary AJAX settings - buttons update the panel in order to load the database.ascx .
And Finally, this is Register.ascx.cs:
public event EventHandler BtnClick;
protected
void bttRegister_Click(object sender, EventArgs e)
        {
            Telerik.ActiveSkill.UI.bizFrame.MyConnection myconn = new Telerik.ActiveSkill.UI.bizFrame.MyConnection();
            if (myconn.CheckUser(txtUser.Text)==false)
            {
 
                Literal1.Text = " Sorry, this string is illegal or Exits";
            }
            else if( myconn.ChechPass(txtPass.Text)==false)
                {
                    Literal2.Text="Only Alpha Character and Number. Min length is 4 and Max is 20";
                }
            else if (txtPass.Text!=txtConfirmPass.Text)
            {
                Literal3.Text= " Confirm password doesn't match Password";
            }
            else if (myconn.CheckEmail(txtEmail.Text) == false)
            {
                Literal4.Text = " Email isn't illegal or Exits";
            }
            else
            {
               
               string Pass = myconn.EncodeMD5(txtPass.Text).Substring(0,20);
 
                myconn.Insertuser(txtUser.Text, Pass, txtEmail.Text);
                MCSIsmi.bizFrame.Utility.ShowErrorFunction.ShowError(this.Page, "Ban đã đăng ký thành công");
               // Control Load = LoadControl("Main.aspx");
 
                 
            }
            if (BtnClick != null)
            {
                BtnClick(sender, e);
            }
        }
No code - behind in Database.ascx.cs

My problem is when I debug, VS appears error "Object reference not set to an instance of an object." at AjaxManager.AjaxSettings.AddAjaxSetting(AjaxButtonLoad, MyPanel);
I had tried to some way but I cann't fix it. When I tested, I saw AjaxButtonLoad was fine " Text= Register", hmmmmm and I didn't know what problem is.
If I configed direct on RadajaxManager in Main.Master between ContentPlaceHolder 4 and Panel1, It was fine. And I want to Load when I put Register.ascx and Database.ascx direct on Main.aspx, not :
Page.Master.FindControl("ContentPlaceHolder4").Controls.Add(LoadControl("Register.ascx"));
            Page.Master.FindControl("ContentPlaceHolder4").Controls[1].ID = "Register1";
Page.Master.FindControl("ContentPlaceHolder3").Controls.Add(LoadControl("Database.ascx"));
Page.Master.FindControl("ContentPlaceHolder3").Controls[1].ID = "Database1";
Any help ? Thanks a lot!!!!
0
Maria Ilieva
Telerik team
answered on 11 Oct 2010, 01:57 PM
Hello long,

The posted code looks ok to me.
As the provided information is not enough to isolate the root cause of the issue you are facing, please prepare a simple, fully runnable reproduction demo, open a new support ticket and send it to us along with very detailed reproduction steps and explanations and we will debug it locally and we will do our best to help.

Regards,
Maria Ilieva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
long
Top achievements
Rank 1
answered on 12 Oct 2010, 02:13 AM
Now It works good. I don't know why, I config direct on RadAjaxManager on Main.aspx between Contentplaceholder4 and ContentPlaceholder3 that not need to use code-behind to create.
This is code in Main.aspx.cs
protected override bool OnBubbleEvent(object source, System.EventArgs args)
        {
            CommandEventArgs commandArgs = args as CommandEventArgs;
            //determine whether to load the user control depending on bubbled button command
            if (commandArgs != null)
            {
                if (commandArgs.CommandName == "Load")
                {
                 //  Page.Master.FindControl("ContentPlaceHolder3").Controls.Add(LoadControl("Database.ascx"));
                   // Page.Master.FindControl("ContentPlaceHolder3").Controls[1].ID = "Database1";
                RadGrid radgrid=(RadGrid)Page.Master.FindControl("ContentPlaceHolder3").FindControl("Database1").FindControl("RadGrid1");
                radgrid.Rebind();
                }
                //else if (commandArgs.CommandName == "Clear")
                //{
                //    //do nothing. the control won't be loaded anyway
                //}
            }
            return base.OnBubbleEvent(source, args);
        }
and a little in Register.ascx.cs
public event EventHandler BtnClick;
 if (BtnClick != null)
            {
                BtnClick(sender, e);
            }
Thanks a lot , Telerik, and If can, I hope u can show me in this topic http://www.telerik.com/community/forums/aspnet-ajax/grid/custom-edit-form-with-web-user-control.aspx
0
Maria Ilieva
Telerik team
answered on 14 Oct 2010, 01:01 PM
Hi long,

I'm glad that you have mentioned to find solution for your issue. Do not hesitate to contact us if further issues appear.


All the best,
Maria Ilieva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Ajax
Asked by
long
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
long
Top achievements
Rank 1
Share this question
or