471,073 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

need to update and display profile property through dropdownlist

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
Jan 5 '06 #1
1 1778
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.
"Trevor Bezotte" <me******@newsgroups.nospam> wrote in message news:%2***************@TK2MSFTNGP09.phx.gbl...
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
Jan 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Terry Olsen | last post: by
reply views Thread by Miguel Dias Moura | last post: by
4 posts views Thread by dsimmons | last post: by
reply views Thread by Mike P | last post: by
1 post views Thread by shapper | last post: by
9 posts views Thread by Kirk | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.