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

Postback Issue

12 Answers 88 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
El
Top achievements
Rank 1
El asked on 16 Nov 2010, 04:47 PM
I have loaded user control in content page. I want it loads some data only if it's not postback because later i need to update this data.
Obviously it is always postback so i can't update the data properly. I tried with checking CallBack but it's always true.
Please suggest what to do. Thanks

12 Answers, 1 is accepted

Sort by
0
El
Top achievements
Rank 1
answered on 17 Nov 2010, 09:51 AM
* bump *

Am i black listed or what?

I asked several questions in the last few days and none of them were answered. I even created support ticket but it was never answered too.

Thanks

NOTE:

Means, i can load the user contols with no problem.

But, in one of the USER CONTROLS i need to populate some fields with DB data and then update it.

e.g. user Control 1:

if(!Page.IsPostBack){

 // populate textboxes and dropdown lists

}

But it never happens as it's always PostBack in AJAX.

If i ommit IsPostBack checking it works fine but, if i want to UPDATE the data changing the textbox and dropdownlist values it does not work becuase it always populate these controls again and again with the old data.

I hope i explained it well this time. Thanks
0
Vasil
Telerik team
answered on 17 Nov 2010, 03:34 PM
Hello El,

Your support tickets was closed, because you posted the same question in the forum. It is better to continue the communication in one thread.

What you are probably looking for is:
if (!ScriptManager.GetCurrent(Page).IsInAsyncPostBack)
{
}

Check this site for more information.
You can use the attribute in Session state , to count how many times you did AsyncPostBack.

Kind regards,
Vasil
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
El
Top achievements
Rank 1
answered on 17 Nov 2010, 11:16 PM
Ok but AsyncPostBack happens after each TabClick which is not what i want. I need it to work just like IsPostBack and load data only when the user control is loaded very first time.

As per the tickets; it happens often that i post in forums and then you ask me to create a support ticket to get a further help. That's why this time, i created ticket right after forum post. Sorry if it's not according the rules.

Thanks
0
El
Top achievements
Rank 1
answered on 18 Nov 2010, 12:59 AM
actually i managed it to work somehow but now it works only in Internet Explorer. In Firefox it does nothing. Just hangs and it seems that the ajax request is never fired.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim parentajax As RadAjaxManager = CType(Parent.FindControl("ParentAjaxManager"), RadAjaxManager)
 
        If parentajax.IsAjaxRequest Then
            PopulateMyFields()
        End If       
    End Sub

Is it sort of bug or what?
0
Vasil
Telerik team
answered on 22 Nov 2010, 02:19 PM
Hello El,

Try the following code and you will see that IsPostBack works also if the control is ajaxified. First time, you will see the numbers from 1 to 5 (in the first page), and when performing postback (using paging for example), you will see that the grid binds to another DataSource with strings (p1 - p6).
You can use the same approach for populating data in other controls.

.aspx:
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<div>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="5">
    </telerik:RadGrid>
</div>
</form>
.cs:
public void Page_Load(object sender, System.EventArgs e)
{
    if (!IsPostBack)
    {
        RadGrid1.DataSource = new string[] { "1", "2", "3", "4", "5", "6" };
    }
    else
    {
        RadGrid1.DataSource = new string[] { "p1", "p2", "p3", "p4", "p5", "p6" };
    }
}

Regards,
Vasil
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
El
Top achievements
Rank 1
answered on 22 Nov 2010, 07:03 PM
That's simply no true!
Add RadTabStrip and RadMultiPage controls to the parent page and then use the Load On Demand practice to load the USER CONTROLS respectively.
It is always POSTBACK. Even the solution i found is not the final solution.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim parentajax As RadAjaxManager = CType(Parent.FindControl("ParentAjaxManager"), RadAjaxManager)
  
        If parentajax.IsAjaxRequest Then
            PopulateMyFields()
        End If      
End Sub

It is fired whenever radajaxmanager request happens while i need something that would make it load data only when it's loaded very first time. However it works if you want to update the data.

Another issue that i noticed with the RadAjaxManager is that the first user control that is loaded in the very first pageview is not firing Load event handler. Rather it happens when you click another tab page and then back to the first page. Weird!

Please suggest something

0
El
Top achievements
Rank 1
answered on 23 Nov 2010, 02:29 PM
If i remove all if statements it loads the data properly but, i can't update this data in that way.

I just need to find a way to load data on INITIAL PAGE LOAD. But i really don;t know how do i do that. Very weird situation.

Thank you
0
Vasil
Telerik team
answered on 23 Nov 2010, 04:17 PM
Hello El,

You can use Session state to see what is going on.

.cs:
if (Session["I_am_here_for_first_time"] == null)
{
    Session["I_am_here_for_first_time"] = true;
    //do initializations here
}
else
{
    Session["I_am_here_for_first_time"] = false;
    //do updates here   
}

I mentioned it before, but probably it was not clear enough what I meant.

Sincerely yours,
Vasil
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
El
Top achievements
Rank 1
answered on 27 Nov 2010, 02:32 PM
Ok it seems to be the best solution so far. However i would expect AJAX manager having a built-in method to check it's not postback.

Btw, may i use ViewState (i can't test at the moment) instead Session object as i cannot increase the timeout of the Session so it expires after 20 minutes?

Thanks
0
Vasil
Telerik team
answered on 01 Dec 2010, 12:31 PM
Hello El,

You can use ViewState in your case. Also you can actually check if your control has some DataSource, from previous postback, and decide to update it or initialize it.

Sincerely yours,
Vasil
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
El
Top achievements
Rank 1
answered on 06 Dec 2010, 11:29 PM
I can't use ViewState nor Session object. If i do it updates the all accounts to firstly loaded data. e.g. if i load customer #1 info and then i try to load user #2 the user #2 data will be updated with the data of user #1.

Please suggest something else. Thanks
0
Vasil
Telerik team
answered on 08 Dec 2010, 02:45 PM
Hello El,

I am not sure how you update this data. Note that controls are showing the data that you give them. If they show different user's data, probably the update function that you use is not correct.

You can open a formal support ticket, and send us your code. Please also explain in details what exactly is the problem.

Greetings,
Vasil
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Ajax
Asked by
El
Top achievements
Rank 1
Answers by
El
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or