DropDownList losing data on page postback
-
Thursday, March 06, 2008 3:12 AM
Not sure if anyone every had this problem but my custom aspx page loses all the value and text when I hit the asp submit button.
The dropdownlist is loaded with crmservice calls to the entity on pageload in my asp.net webpage code-behind.
Then when I make a selection, and the page runs my button event on the code-behind, it resets the dropdownlist to blank.
Anyone know what's going on?
Thanks
All Replies
-
Thursday, March 06, 2008 3:30 AMModerator
use
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
BindDropDownList1();
}
}REgards,
Imran
http://microsoftcrm3.blogspot.com
-
Thursday, March 06, 2008 3:55 AM
Binding the dropdownlist doesn't work for me. I call a function to bind the dropdownlist and made my void Page_Load private and it still doesn't keep it's life cycle.
Here is a sample of my code
Code Snippet**** Code-Behind ****
use CrmSdk stuff...
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
Authenticates CRM codes...
WhoAmIRequest stuff...
BindDropDownList(crmService);
}
}
private void BindDropDownList(crmService)
{
RetrieveMultipleResponse
retrievedUsers = (RetrieveMultipleResponse)crmService.Execute(retrieve);foreach
(systemuser tempuser in retrievedUsers.BusinessEntityCollection.BusinessEntities){
new ListItem(tempuser.fullname.ToString(), tempuser.systemuserid.Value.ToString()));DropDownList.Items.Add(
}
}
protected void SaveButton_Click (object sender, EventArgs e)
{
string txt = DropDownList.SelectedItem.Text; <-- this is blank on page reload and throws an null error
}
**** Code-InFront ****
<html><body>
<asp:Button Text="Save" OnClick="SaveButton_Click" runat="server" />
</body>
</html>
I have an ISV buttons configuration to launch a JavaScript="window.open('default.aspx?params');" and another to launch a URL="default.aspx" PassParams="1" WinMode="0" for both.
Seems like CRM 4.0 doesn't like to share the app pool life cycle with my asp page.
-
Thursday, March 06, 2008 8:52 AM
Hi.
Make sure that the EnableViewState equals true for the page and DropDownList.
You can also repopulate the DropDownList in the SaveButton_Click event like so;
protected void SaveButton_Click (object sender, EventArgs e)
{
string txt = DropDownList.SelectedItem.Text; <-- this is blank on page
//reload and throws an null error
//more code here
DropDownList.SelectedValue = txt;
}
Or
Use Ajax instead of a regular submit button to avoid page refresh.
Cheers,
Adi
-
Thursday, March 06, 2008 8:56 AMModerator
Is there EnablePageViewState of asp.net page.
Check if you reload on save button.
Regards,
Imran
http://microsoftcrm3.blogspot.com
-
Wednesday, March 12, 2008 7:15 PM
Hi,
I'm getting the same problem..
Well I put the "autopostback" on true and the "enableviewstate" on true of the "dropdownlist", but it still doesn't work
It still loses all his data when I do a "Postback"...
has someone an answer for this problem ??? Tried a lot

Kind regards,
Frederic Demeilliez
-
Wednesday, March 12, 2008 7:20 PM
put enableViewState in your page directive:
<%
@ Page Language="C#" AutoEventWireup="true" CodeBehind="Accept.aspx.cs" Inherits="MyApp.Accept" EnableViewState="true" %>or in Web.Config:
<
system.web><
pages buffer="true" enableViewState="true" /></
system.web>Goodluck
- Proposed As Answer by Hanno Z Thursday, January 14, 2010 12:55 PM
-
Wednesday, March 12, 2008 7:39 PM
Hi,
Fantastic !!!! My problem is solved !!! Thx

Kind regards,
Demeilliez Frederic
www.despiere.com
- Proposed As Answer by amrgame Sunday, November 15, 2009 11:02 AM
-
Sunday, November 15, 2009 11:03 AM
hello brother how can i solve it pleaseHi,
Fantastic !!!! My problem is solved !!! Thx

Kind regards,
Demeilliez Frederic
www.despiere.com
-
Thursday, January 14, 2010 12:55 PM
That was just what I needed! I was having the same problem, I already tried to enable ViewState in de @Page directive of the aspx page, but that didn't help. But enabling the ViewState in web.config did the trick! (One small thing, you don't need to set buffer to true explicitly, since true is the default value ;) )put enableViewState in your page directive:
<% @ Page Language ="C#" AutoEventWireup ="true" CodeBehind ="Accept.aspx.cs" Inherits ="MyApp.Accept" EnableViewState ="true" %>
or in Web.Config:
< system.web >
< pages buffer = " true " enableViewState = " true " />
</ system.web >
Goodluck
-
Thursday, May 03, 2012 6:26 AMThanks a lot .