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

Radgrid User Control - IsPostBack always true

10 Answers 286 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 1
Marcus asked on 07 Nov 2008, 05:37 PM
Hi, I have a radGrid that uses a user control to handle Insert/Edit. The user control is a popup (EditMode="PopUp") and it all appears to work fine. The only problem is that in the Form Load event of my popup, IsPostBack is always true. I guess this is because it has loaded in an Ajax Panel?

Any thoughts how I can get round this?

Thanks!

10 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 10 Nov 2008, 07:30 AM
Hello Marcus,

Edit forms in the grid are loaded on post-back event (when you click edit button) and that is why IsPostBack is always true.

Greetings,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Marcus
Top achievements
Rank 1
answered on 10 Nov 2008, 09:26 AM
Hi Vlad, Thanks for the feedback.

So can I ever tell if it's a page postback? Also, whenever my usercontrol does a postback it repositions itself back to where it was initially (before I dragge it to a new place). Is there any way the user control can be 'pinned' like the radWindow can?

Thanks very much,

Marcus.
0
Iana Tsolova
Telerik team
answered on 13 Nov 2008, 11:54 AM
Hello Marcus,

Could you please elaborate more on your scenario? Sending your code (page/user control/code) could help us to get to the source of the issue and find a resolution for you.

Kind regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Marcus
Top achievements
Rank 1
answered on 13 Nov 2008, 12:25 PM

Hi Iana,

Sure, when I click 'edit' on my grid I show a pop-up user control ('Test2.ascx'). In my form load event of this user control I check to see if it's a postback so that I can initialise the page on the first time through (normal .NET stuff). However, the IsPostBack property is true the first time in (I'd expect this to be false).

Here's the code for my main rid

 

<

script type="text/javascript">

 

 

 

 

var popUp;

 

 

function PopUpShowing(sender, eventArgs)

 

{

popUp = eventArgs.get_popUp();

 

var gridWidth = sender.get_element().offsetWidth;

 

 

var gridHeight = sender.get_element().offsetHeight;

 

 

var popUpWidth = popUp.style.width.substr(0,popUp.style.width.indexOf("px"));

 

 

var popUpHeight = popUp.style.height.substr(0,popUp.style.height.indexOf("px"));

 

popUp.style.left = ((gridWidth - popUpWidth)/2 + sender.get_element().offsetLeft).toString() +

"px";

 

popUp.style.top = ((gridHeight - popUpHeight)/2 + sender.get_element().offsetTop).toString() +

"px";

 

}

 

 

</

script>

 

 

 

 

 

 

<!-- content start -->

 

 

<

telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

 

 

 

 

<AjaxSettings>

 

 

 

 

<telerik:AjaxSetting AjaxControlID="RadGrid1">

 

 

 

 

<UpdatedControls>

 

 

 

 

<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />

 

 

 

 

</UpdatedControls>

 

 

 

 

</telerik:AjaxSetting>

 

 

 

 

</AjaxSettings>

 

</

telerik:RadAjaxManager>

 

<

telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px"

 

 

 

 

Width="75px" Transparency="20">

 

 

 

 

<img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>'

 

 

 

 

style="border: 0;" />

 

</

telerik:RadAjaxLoadingPanel>

 

<

telerik:RadGrid AutoGenerateEditColumn="True" AutoGenerateColumns="False"

 

 

OnItemCreated="RadGrid1_ItemCreated" OnItemCommand="RadGrid1_ItemCommand"

 

 

ID="RadGrid1" runat="server" OnExcelMLExportStylesCreated="RadGrid1_ExcelMLExportStylesCreated"

 

 

 

 

OnExcelMLExportRowCreated="RadGrid1_ExcelMLExportRowCreated" AllowPaging="True" AllowSorting="True" DataSourceID="ObjectDataSource1" GridLines="None"

 

 

 

 

Skin="Telerik" ShowGroupPanel="True" ShowFooter="True"

 

 

OnUpdateCommand="RadGrid1_UpdateCommand"

 

 

OnInsertCommand="RadGrid1_InsertCommand" AllowFilteringByColumn="True">

 

 

 

 

<MasterTableView CommandItemDisplay="Top" DataSourceID="ObjectDataSource1" EditMode="PopUp" DataKeyNames="ID" PageSize="5">

 

 

 

 

<RowIndicatorColumn>

 

 

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

 

 

</RowIndicatorColumn>

 

 

 

 

<ExpandCollapseColumn>

 

 

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

 

 

</ExpandCollapseColumn>

 

 

 

 

<Columns>

 

 

 

 

<telerik:GridEditCommandColumn UniqueName="EditCommandColumn">

 

 

 

 

</telerik:GridEditCommandColumn>

 

 

 

 

<telerik:GridBoundColumn DataField="Id" Visible="false" DataType="System.Int32" HeaderText="Id"

 

 

 

 

SortExpression="Id" UniqueName="Id">

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

<telerik:GridBoundColumn DataField="InvestmentHouse" HeaderText="Investment House"

 

 

 

 

SortExpression="InvestmentHouse" UniqueName="InvestmentHouse">

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

<telerik:GridBoundColumn DataField="FundName" HeaderText="Fund Name" SortExpression="FundName"

 

 

 

 

UniqueName="FundName">

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

<telerik:GridBoundColumn DataField="Sector" HeaderText="IMA Sector" SortExpression="Sector"

 

 

 

 

UniqueName="Sector">

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

<telerik:GridBoundColumn DataField="Category" HeaderText="Fixed Interest Focus"

 

 

 

 

SortExpression="Category" UniqueName="Category">

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

<telerik:GridBoundColumn DataField="EquityMarketCap" HeaderText="Equity Market Cap"

 

 

 

 

SortExpression="EquityMarketCap" UniqueName="EquityMarketCap">

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

<telerik:GridBoundColumn DataField="EquityInvestment" HeaderText="Equity Investment Style"

 

 

 

 

SortExpression="EquityInvestment" UniqueName="EquityInvestment">

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

<telerik:GridBoundColumn DataField="OBSRRating" HeaderText="OBSR Rating"

 

 

 

 

SortExpression="OBSRRating" UniqueName="OBSRRating">

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

</Columns>

 

 

 

 

<EditFormSettings CaptionFormatString="Edit Fund: {0}" CaptionDataField="FundName" PopUpSettings-ZIndex="4000" EditColumn-Resizable="true" PopUpSettings-Modal="true" UserControlName="~/desktopmodules/FundManager/Test2.ascx" PopUpSettings-ScrollBars="None" EditFormType="WebUserControl">

 

 

 

 

<EditColumn AutoPostBackOnFilter="true" UniqueName="EditCommandColumn1">

 

 

 

 

</EditColumn>

 

<

PopUpSettings ScrollBars="None" Modal="True" ZIndex="4000"></PopUpSettings>

 

 

 

 

</EditFormSettings>

 

 

 

 

</MasterTableView>

 

 

 

 

<SortingSettings SortedBackColor="Azure" />

 

 

 

 

<ClientSettings EnableRowHoverStyle="true" AllowDragToGroup="True">

 

 

 

 

<Selecting AllowRowSelect="True" />

 

 

 

 

<ClientEvents OnPopUpShowing="PopUpShowing" />

 

 

 

 

</ClientSettings>

 

 

 

 

<FilterMenu EnableTheming="True" Skin="Hay">

 

 

 

 

<CollapseAnimation Type="OutElastic" Duration="200"></CollapseAnimation>

 

 

 

 

</FilterMenu>

 

</

telerik:RadGrid>

 


Then, in my user control (Test2.ascx) I do this in my page load ..

 

protected void Page_Load(object sender, EventArgs e)

 

{

 

try

 

{

 

if (!IsPostBack)

 

{

    //do something here...
}

}


And IsPostBack is always true...

Thanks,

Marcus. 
0
Iana Tsolova
Telerik team
answered on 14 Nov 2008, 01:17 PM
Hello Marcus,

Thank you for sending your code.

I followed your scenario in order to replicate the issue. Please try the attached sample and let me know how it works on your end and if I missed something from your logic.

Regarding the IsPostBack: When you click the edit button you perform a postback on which postback the user control is loaded. That is why the Page.IsPostBack property is always true in the user control.

Sincerely yours,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Bridget
Top achievements
Rank 1
answered on 30 Mar 2011, 04:49 PM
Hello,

Was there ever a work-around to determining when to Initialize the control, if IsPostBack is always true?  We are running into a situation where we need to DataBind a dropdownlist in our formtemplate usercontrol, but if we DataBind on every postback, then we lose the selected value.

How can we determine if this is the initial loading of the FormTemplate control, so that we only initialize the form at the appropriate time?

Thanks,
-Bridget
0
Iana Tsolova
Telerik team
answered on 04 Apr 2011, 08:15 AM
Hi Bridget,

The best place for data-binding the DropDownList in the FormTemplate is the ItemDataBound event of the grid. You can refer to the below articles for more information:
http://www.telerik.com/help/aspnet-ajax/grid-custom-edit-forms.html
http://www.telerik.com/help/aspnet-ajax/grid-operations-with-dropdownlist-in-edititemtemplate.html

Regards,
Iana
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
Eva
Top achievements
Rank 1
answered on 29 Mar 2012, 10:04 PM
I'm having the same issue.

In my case i have to load and update two date field in the user control, since ispostback is always true, how do i achive this behaviour.

0
Rohan
Top achievements
Rank 1
answered on 20 Dec 2012, 02:14 PM

hi all,
 I have one user control with rad grid and rad window . The rad Grid is generated dynamically on page load of user control in is postback. This is user control work in all my conditions with defined functionally …… My problem is – whenever i add this user control to to rad grid edit user control –then my user control (rad grid) columns are not created because of postback  gets true of radgrid edit …..

Please provide and way of solution to work out …….
Thank You

0
Eyup
Telerik team
answered on 24 Dec 2012, 02:41 PM
Hello Rohan,

I have already provided an answer in the following thread:
http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-edit-form-interim-postbacks-before-final-update.aspx

Please note that avoiding multiple threads with similar issues will enable us to respond more quickly and efficiently to your posts.

Regards,
Eyup
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
Grid
Asked by
Marcus
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Marcus
Top achievements
Rank 1
Iana Tsolova
Telerik team
Bridget
Top achievements
Rank 1
Eva
Top achievements
Rank 1
Rohan
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or