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

RadAjaxManager and linkbutton click event

6 Answers 254 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Mariam
Top achievements
Rank 1
Mariam asked on 22 Aug 2012, 08:25 AM
hello, i have some linkbuttons like manu items with onClick event, witch set css attributes and loading different usercontrols in placehoder control. 
here is code for one of my linkbuttons:

protected void homeBtn_Click(object sender, EventArgs e)
   {
 
       ControlPath = "Mainpage.ascx";
       LoadUserControl();
       homeBtnH4.Attributes.Add("class", "activem");
       eventBtnH4.Attributes.Remove("class");
 
       
   }

here is the way I'm loading usercontrols dynamicaly in placehodler:

private void LoadUserControl()
   {
       if (!string.IsNullOrEmpty(ControlPath))
       {
           placeHolder1.Controls.Clear();
           UserControl uc = (UserControl)LoadControl(ControlPath);
      
           placeHolder1.Controls.Add(uc);
       }
   }
 
 
   public string ControlPath
   {
       get
       {
           if (ViewState["controlPath"] != null)
               return Convert.ToString(ViewState["controlPath"]);
           else
               return null;
       }
 
       set
       {
           ViewState["controlPath"] = value;
       }
   }

now i want to use RadAjaxManager to update div element where is placed placeholder:

<div class="contentholder" id="updatepanel" runat="server" >
  <asp:PlaceHolder ID="placeHolder1" runat="server"></asp:PlaceHolder>
</div>

here is my ajax code:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
   <AjaxSettings>
               
           <telerik:AjaxSetting AjaxControlID="homeBtn">
               <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="updatepanel" LoadingPanelID="RadAjaxLoadingPanel1" >
                   </telerik:AjaxUpdatedControl>
                    
               </UpdatedControls>
           </telerik:AjaxSetting>
 
   </AjaxSettings>
   </telerik:RadAjaxManager>
       <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">
   </telerik:RadAjaxLoadingPanel>

problem is that , homebtn click doesn't work properly , css class don't add and on second click it doesn't load usercontrol at all.
sorry for my bad English, not native language.. 

6 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 22 Aug 2012, 12:59 PM
Hi Mariam,

The reason for the described problem could be due to incorrect loading of the UserControls. If you are changing the userControl on a button click event you should load the new UserControls inside the button's click handler and use Page's Init event to load the same UserControl which has been loaded in the previous page request.

I would also suggest you to review the following online resources which elaborates on Loading UserControls with Ajax:
http://www.telerik.com/help/aspnet-ajax/ajax-load-user-controls.html
http://demos.telerik.com/aspnet-ajax/ajax/examples/common/loadingusercontrols/defaultcs.aspx

All the best,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Mariam
Top achievements
Rank 1
answered on 22 Aug 2012, 02:05 PM
thx for reply, I'll have a look )
0
Mariam
Top achievements
Rank 1
answered on 22 Aug 2012, 03:02 PM
so strange, i can't understand what's goning on 

i corrected my usercontrol loading method as was written above http://www.telerik.com/help/aspnet-ajax/ajax-load-user-controls.html 

everything is working properly, except of "add.attribute" onClick event

I'm not using masterpage. i'm loadnig controls in aspx page. here is code again:

    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>  
 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="homeBtn">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="placeHolder1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
       
    </AjaxSettings>
</telerik:RadAjaxManager>
<h4 runat="server" id="homeBtnH4" >
 <img src="style/img/icons/home.png" />
  <asp:LinkButton ID="homeBtn" runat="server" Text="მთავარი" CssClass="titles" OnClick="homeBtn_Click"></asp:LinkButton>
</h4>
<asp:Panel ID="placeHolder1" runat="server">
</asp:Panel>

and code behind:

protected void Page_Load(object sender, EventArgs e)
    {
        if (this.CurrentControl != string.Empty)
        {
            LoadMyUserControl(CurrentControl, placeHolder1);
        }
        if (!IsPostBack)
        {
            homeBtnH4.Attributes.Add("class", "activem");
          
        }
 
    }
 
 
 private string CurrentControl
    {
        get
        {
            return this.ViewState["CurrentControl"] == null ? string.Empty : (string)this.ViewState["CurrentControl"];
        }
        set
        {
            this.ViewState["CurrentControl"] = value;
        }
    }
    private void LoadMyUserControl(string controlName, Control parent)
    {
        parent.Controls.Clear();
        UserControl MyControl = (UserControl)LoadControl(controlName);
        string userControlID = controlName.Split('.')[0];
        MyControl.ID = userControlID.Replace("/", "").Replace("~", "");
        parent.Controls.Add(MyControl);
        this.CurrentControl = controlName;
    }
protected void homeBtn_Click(object sender, EventArgs e)
    {
        this.LoadMyUserControl("Mainpage.ascx", placeHolder1);
        
     homeBtnH4.Attributes.Add("class", "activem");
    
    }

0
Pavlina
Telerik team
answered on 27 Aug 2012, 03:34 PM
Hello,

As I can see, you are trying to add attribute to button with ID = homeBtnH4, which I can not see in the provided code. Can you send us the whole problematic code, so we can try to replicate the issue locally?

Greetings,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Mariam
Top achievements
Rank 1
answered on 27 Aug 2012, 07:08 PM
i wrote whole problematic code which is in my aspx page  above

there is H4 element with ID  = "homeBtnH4 ", not button.
i tried to add attribute on h4 with linkbutton onClick event and it doesn't work... but when i remove telerik:RadAjaxManager everithing works fine.



<h4 runat="server" id="homeBtnH4" >
 <img src="style/img/icons/home.png" />
  <asp:LinkButton ID="homeBtn" runat="server" Text="მთავარი" CssClass="titles" OnClick="homeBtn_Click"></asp:LinkButton>
</h4>
<asp:Panel ID="placeHolder1" runat="server">
</asp:Panel>

thx again
0
Pavlina
Telerik team
answered on 30 Aug 2012, 08:56 PM
Hi,

Thank you for the clarification, however it will be best l if you could send us sample runnable application that represents the problem you are facing via support ticket. We will debug it locally and advise you further.

All the best,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Ajax
Asked by
Mariam
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Mariam
Top achievements
Rank 1
Share this question
or