need to update and display profile property through dropdownlist

T

Trevor Bezotte

Hi,

I'm new to asp.net. I am having trouble updating and displaying a profile property through a dropdownlist. I believe the problem has something to do with autoeventwireup but I'm not sure. If I change the selection in the dropdownlist and click Button1, the profiles database gets updated and the control shows my new selection, but when I browse to a different page and come back to this page, the dropdownlist gets set back to the default selection (the first item in the list). Why is this happening and how do I fix it?

Here is my code:

<%@ Page Language="VB" MasterPageFile="~/AppMaster.master" AutoEventWireup="false" CodeFile="Profiles.aspx.vb" Inherits="Profiles" title="My Apps" StylesheetTheme="Paper" %>
<asp:Content ID="Content1" ContentPlaceHolderID="mainCopy" Runat="Server">
<div class="container" style="left: 0px; position: relative; top: 0px; height: 8%">
<h2>
Personalization Options</h2>
<p class="teaser">
<asp:Label ID="Label1" runat="server" Style="left: 1px; position: relative; top: 6px"
Text="Manufacturer Interest:" Width="142px"></asp:Label>
&nbsp;
</p>
<div class="readmore">
<asp:DropDownList ID="DropDownList1" runat="server" Style="left: 33px; position: relative;
top: -22px" Width="193px">
<asp:ListItem>Oracle</asp:ListItem>
<asp:ListItem>Microsoft</asp:ListItem>
<asp:ListItem>Siebel</asp:ListItem>
<asp:ListItem>Optio</asp:ListItem>
<asp:ListItem>Primavera</asp:ListItem>
<asp:ListItem>Meridian</asp:ListItem>
<asp:ListItem>Autodesk</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Style="left: -1px; position: relative; top: 48px"
Text="Save Profile" OnClick="Button1_Click" /><br />
<br />
<br />
<a href="javascript:;" title="More info"></a>&nbsp;</div>
</div>
</asp:Content>

Code Behind:

Partial Class Profiles
Inherits System.Web.UI.Page

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
DropDownList1.SelectedValue = Profile.manufacturerInterest
End Sub

Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Profile.manufacturerInterest = DropDownList1.SelectedValue
End Sub

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub

End Class

Thank you for your help.
Trevor
 
T

Trevor Bezotte

I didn't realize that page_load was getting fired before button_click, I added a check for IsPostBack and that solved the problem.

Thanks.
Hi,

I'm new to asp.net. I am having trouble updating and displaying a profile property through a dropdownlist. I believe the problem has something to do with autoeventwireup but I'm not sure. If I change the selection in the dropdownlist and click Button1, the profiles database gets updated and the control shows my new selection, but when I browse to a different page and come back to this page, the dropdownlist gets set back to the default selection (the first item in the list). Why is this happening and how do I fix it?

Here is my code:

<%@ Page Language="VB" MasterPageFile="~/AppMaster.master" AutoEventWireup="false" CodeFile="Profiles.aspx.vb" Inherits="Profiles" title="My Apps" StylesheetTheme="Paper" %>
<asp:Content ID="Content1" ContentPlaceHolderID="mainCopy" Runat="Server">
<div class="container" style="left: 0px; position: relative; top: 0px; height: 8%">
<h2>
Personalization Options</h2>
<p class="teaser">
<asp:Label ID="Label1" runat="server" Style="left: 1px; position: relative; top: 6px"
Text="Manufacturer Interest:" Width="142px"></asp:Label>
&nbsp;
</p>
<div class="readmore">
<asp:DropDownList ID="DropDownList1" runat="server" Style="left: 33px; position: relative;
top: -22px" Width="193px">
<asp:ListItem>Oracle</asp:ListItem>
<asp:ListItem>Microsoft</asp:ListItem>
<asp:ListItem>Siebel</asp:ListItem>
<asp:ListItem>Optio</asp:ListItem>
<asp:ListItem>Primavera</asp:ListItem>
<asp:ListItem>Meridian</asp:ListItem>
<asp:ListItem>Autodesk</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Style="left: -1px; position: relative; top: 48px"
Text="Save Profile" OnClick="Button1_Click" /><br />
<br />
<br />
<a href="javascript:;" title="More info"></a>&nbsp;</div>
</div>
</asp:Content>

Code Behind:

Partial Class Profiles
Inherits System.Web.UI.Page

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
DropDownList1.SelectedValue = Profile.manufacturerInterest
End Sub

Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Profile.manufacturerInterest = DropDownList1.SelectedValue
End Sub

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub

End Class

Thank you for your help.
Trevor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top