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

Refresh UserControl after a PostBack?

10 Answers 1413 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
chris_cf
Top achievements
Rank 2
chris_cf asked on 14 Apr 2009, 03:12 AM
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.

10 Answers, 1 is accepted

Sort by
0
Ivan Dimitrov
Telerik team
answered on 16 Apr 2009, 01:19 PM
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.
0
chris_cf
Top achievements
Rank 2
answered on 16 Apr 2009, 07:33 PM
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.
0
Ivan Dimitrov
Telerik team
answered on 17 Apr 2009, 02:09 PM
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.
0
chris_cf
Top achievements
Rank 2
answered on 17 Apr 2009, 02:52 PM
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.


0
chris_cf
Top achievements
Rank 2
answered on 17 Apr 2009, 05:49 PM
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:

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

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?
0
Georgi
Telerik team
answered on 22 Apr 2009, 11:04 AM
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.
0
chris_cf
Top achievements
Rank 2
answered on 22 Apr 2009, 05:20 PM
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.
0
Tonic
Top achievements
Rank 1
answered on 23 Apr 2009, 06:14 AM
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.
0
chris_cf
Top achievements
Rank 2
answered on 23 Apr 2009, 08:55 PM
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).
0
darshan thacker
Top achievements
Rank 1
answered on 17 Apr 2012, 09:49 AM
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 ?

    
Tags
Ajax
Asked by
chris_cf
Top achievements
Rank 2
Answers by
Ivan Dimitrov
Telerik team
chris_cf
Top achievements
Rank 2
Georgi
Telerik team
Tonic
Top achievements
Rank 1
darshan thacker
Top achievements
Rank 1
Share this question
or