Refresh UserControl after a PostBack?

11 posts, 0 answers
  1. chris_cf
    chris_cf avatar
    53 posts
    Member since:
    Jul 2007

    Posted 13 Apr 2009 Link to this post

    I have a sign up form which when a user completes successfully, it logs them in automatically. After the user clicks "Finish", they are presented with a Congratulations page which tells them what their new username and password is. I have a UserControl in another ContentPlaceHolder on the page which is either displays a Login form or the logged in user's info.

    Upon successful completion of signing up, I want to refresh the Login UserControl so that it displays the user's info rather than the login form.

    I am using MasterPages and Sitefinity.
  2. Ivan Dimitrov
    Admin
    Ivan Dimitrov avatar
    78 posts

    Posted 16 Apr 2009 Link to this post

    Hello chris_cf,

    To display the user's info you can use built in ManageUsers control - it should be set in View mode ( by default there are three modes - View, Edit, Insert.

    You can also gather the user info programmatically. Here is a sample below.


     
            // gets currently logged user 
            MembershipUser user = Membership.GetUser(); 
            ProfileBase profile = ProfileBase.Create(user.UserName); 
             
            // create an array of profile values 
            string [] AllData = new string[]{ 
                (string)profile.GetPropertyValue("FirstName"), 
                (string)profile.GetPropertyValue("LastName"
            }; 
            Response.Write( string.Join("<br />", AllData) ); 


    Let us know if there is anything else that we can do for you.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. chris_cf
    chris_cf avatar
    53 posts
    Member since:
    Jul 2007

    Posted 16 Apr 2009 Link to this post

    Hi Ivan,

    I made a custom user control for this. It checks to see if the current user is authenticated. If not, it shows the login form, if they are logged in, it shows the user info.

    On the final step of the sign-up wizard, I have a Finish button which, when clicked, generates a username, adds the user to the database, logs in the user and then shows them the last RadPageView in a RadMultiPage. I have this RadMultiPage wrapped in an RadAjaxPanel because I wanted to Ajaxify the switching of the RadPageViews. However, the custom user control that either shows the login form or user info is in another ContentPlaceHolder on the page. I am using Sitefinity, so it is essentially a Master Page that I am using. The custom user control is not wrapping in a RadAjaxPanel. However, I would like the ability to refresh the custom user control AFTER the Finish button is pressend and AFTER the user is created in the db.

    To further clarify, the sign up form is a custom user control as well.

    I hope this clarifies my situation better.
  5. Ivan Dimitrov
    Admin
    Ivan Dimitrov avatar
    78 posts

    Posted 17 Apr 2009 Link to this post

    Hi chris_cf,

    To update the other control I think that the best way is using AjaxManager control. Please take a look at the following link http://www.telerik.com/help/aspnet-ajax/ajxajaxmanager.html. The controls you have are on a page, so that you should add AjaxManager on the same page and in one of your controls you can find the manager on Page_Load, then update the control you want.

    Example:

      protected void Page_Load(object  sender, EventArgs e) 
       { 
            RadAjaxManager AjaxManager = (RadAjaxManager)this.FindControl("RadAjaxManager1"); 
            AjaxManager.AjaxSettings.AddAjaxSetting(btn, Label1); 
       } 


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. chris_cf
    chris_cf avatar
    53 posts
    Member since:
    Jul 2007

    Posted 17 Apr 2009 Link to this post

    Hi Ivan,

    I can access the custom Login control using this. But my problem is more getting the control to refresh at the right time.

    I can refresh it via JS using the following code:

    function InitiateAjaxRequest(sender, args) { 
                var ajaxManager = $find('<% =Page.Master.FindControl("RadAjaxManager1").ClientID %>'); 
                ajaxManager.ajaxRequest(''); 
            } 

    However, I need this to fire AFTER the Finish button click event has fired. The Finish button click event adds the user to the db. After it adds the user to the db, it switched to another PageView.


  7. chris_cf
    chris_cf avatar
    53 posts
    Member since:
    Jul 2007

    Posted 17 Apr 2009 Link to this post

    On the Page_Load of my Sign up form, I have this:

    protected void Page_Load(object sender, EventArgs e) 
        { 
            RadAjaxManager AjaxManager = (RadAjaxManager)Page.Master.FindControl("RadAjaxManager1"); 
            UserControl uc = (UserControl)Page.Master.FindControl("cphHeader").FindControl("ipLoginTop"); 
            AjaxManager.AjaxSettings.AddAjaxSetting(btnEnroll, uc); 
        } 

    There is a Finish button on the Sign up form that fires an event called EnrollUser:

    1     protected void EnrollUser(object sender, EventArgs e) 
    2     { 
    3             // Add the user 
    4             MembershipUser NewUser = Membership.CreateUser(strUsername, txtPassword.Text, txtEmail.Text, nullnullfalseout Status); 
    5  
    6             // Login the user 
    7             FormsAuthentication.SetAuthCookie(NewUser.UserName, false); 
    8  
    9             // Find the Login control and set visibility of LoggenIn panel 
    10             UserControl uc = (UserControl)Page.Master.FindControl("cphHeader").FindControl("ipLoginTop"); 
    11             uc.FindControl("pnlLoginForm").Visible = false
    12             uc.FindControl("pnlLoggedIn").Visible = true
    13     } 

    However, when pnlLoggedIn is set to Visible, it does not show the info of the user. In fact, it thinks the current user is not authenticated.

    Do you know why this might be?
  8. Georgi
    Admin
    Georgi avatar
    31 posts

    Posted 22 Apr 2009 Link to this post

    Hello Chris,

    I think that you need to validate the user first, before setting the cookie:
    if (Membership.ValidateUser(strUsername, txtPassword.Text.trim())  
    {   
         FormsAuthentication.SetAuthCookie(NewUser.UserName, false);    
         ......  
    }   
     

    Let me know if this helps.

    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  9. chris_cf
    chris_cf avatar
    53 posts
    Member since:
    Jul 2007

    Posted 22 Apr 2009 Link to this post

    I got it working.

    In my sign-up user control, I added this code to the Page_Load

    RadAjaxManager AjaxManager = (RadAjaxManager)Page.Master.FindControl("RadAjaxManager1"); 
    UserControl uc = (UserControl)Page.Master.FindControl("cphHeader").FindControl("ipLoginTop"); 
    AjaxManager.AjaxSettings.AddAjaxSetting(AjaxManager, uc); 

    I have a JS function in the sign-up user control:

            function InitiateAjaxRequest(source, args) { 
                    var ajaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>"); 
                    ajaxManager.ajaxRequest(); 
            } 

    The sign-up user control also has a RadAjaxPanel which I set it's property ClientEvents-OnResponseEnd="InitiateAjaxRequest"

    After doing that, the Login user control was updated as needed.

    I am not sure what adding the AjaxManager to itself as an AjaxSetting does but it worked. Can anyone shed some light on this?

    Also what is the argument that ajaxManager.ajaxRequest(arg) takes? I am not sure of the significance of it.
  10. Tonic
    Tonic avatar
    1 posts
    Member since:
    Apr 2009

    Posted 23 Apr 2009 Link to this post

    Sorry to hijack your thread chris but is the question at hand "how to refresh a control (control2) which is located within a ContentPlaceHolder other than the ContentPlaceHolder containing the Ajaxified control (control1) which is to initiate the refresh operation?".  Or in other words when control1 creates an AjaxPostBack you want control2 to be refreshed, even though they are in different ContentPlaceHolders?

    I am only new to the Telerik controls and have inherited an existing system from another developer and am faced with a similar problem to what I have described above.
  11. chris_cf
    chris_cf avatar
    53 posts
    Member since:
    Jul 2007

    Posted 23 Apr 2009 Link to this post

    Yep, you got it. My previous post says how I accomplished it.

    I had RadAjaxManager in the Master Page. The Enroll form was in its own RadAjaxPanel so it did not use RadAjaxManager. I only use RadAjaxManager to update the second control (the Login control).
  12. darshan thacker
    darshan thacker avatar
    8 posts
    Member since:
    Dec 2009

    Posted 17 Apr 2012 Link to this post

    Hi,

    I have some same kind of functionality where i have two user controlers on one page, and each user control has save page which redirects to other usercontrol view on button click. on this button click i have response.redirect - how to make this call ajaxify ? as this controls are added dynamically to the page so i can't check with findcontrol option. is there any easy way ?

        
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017