Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / June 2006

Tip: Looking for answers? Try searching our database.

"Collision" in DropDownLists from two instances of same UserContro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex Maghen - 07 Jun 2006 03:43 GMT
I have a UserControl which has only one constituent control, a DropDownList.

I am having what seems to be an IMPOSSIBLE situation: In the Page_Load() of
my ASPX, I am setting
  MyCtl1.SomePropery = "A";
  MyCtl2.SomePropery = "B";

Inside my control, I pretty much set the DropDownList (DDL.SelectedValue) to
the SomeProperty.

Now here's the crazy thing that's happening:
If I do what I showed above in Page_Load(), BOTH of my controls will have
the same "B" in their respective DropDownLists. Somehow, the property I am
setting for one of these is getting into the settings for the other. And it's
always the control that's LAST in order in the HTML of my ASPX page whose
value copies to those that came before it. How can this be happeneing?

Alex

Somehow, whichever instance of MyCtl came LAST in the HTML of the ASPX file
will
Steven Cheng[MSFT] - 07 Jun 2006 09:47 GMT
Hi Alex,

I've posted my followup in your previous thread in the aspnet newsgroup:

"Design-Time UserControl Property Setting"

As for the new problem you mentioned here, I think it depend on how to
implement the custom property, are you storing the property data into a
shared place that multiple usercontrols instances could overwrite it? For
exapmle, if you use a static varitable , then all the control instance may
share the same variable instance.  Anyway, for your convenience, I'll paste
my test usercontrol(modified one according to your another thread) here,
you can have a test against it to see whether it works(based on my local
test it works well):

=======ascx=============
<asp:Label ID="lblCategories" runat="server" Text="Categories:
"></asp:Label>
<asp:DropDownList ID="lstCategories" runat="server"
OnSelectedIndexChanged="lstCategories_SelectedIndexChanged">
</asp:DropDownList>

==========code behind==========
public partial class UserControls_ddl_ListUC : System.Web.UI.UserControl
{

   private int _count;

   public int Count
   {
       get { return _count; }
       set { _count = value; }
   }

   public string SelectedValue
   {
       get { return ViewState["_selectedvalue"] as string; }
       set
       {
           ViewState["_selectedvalue"] = value;
       }
   }

 

   protected void Page_Load(object sender, EventArgs e)
   {

     
       if (!IsPostBack)
       {
           string sql = "select TOP {0} CategoryID, CategoryName from
Categories";

           SqlConnection conn = new
SqlConnection(WebConfigurationManager.ConnectionStrings["LocalNorthwindConnS
tr"].ConnectionString);

           conn.Open();

           SqlCommand comm = new SqlCommand(string.Format(sql, _count),
conn);
           SqlDataReader reader =
comm.ExecuteReader(CommandBehavior.CloseConnection);

           lstCategories.DataSource = reader;
           lstCategories.DataTextField = "CategoryName";
           lstCategories.DataValueField = "CategoryName";

           lstCategories.DataBind();

           reader.Close();

         
       }

   }

   protected void Page_PreRender(object sender, EventArgs e)
   {
       lstCategories.SelectedValue = SelectedValue;

   }

   protected void lstCategories_SelectedIndexChanged(object sender,
EventArgs e)
   {
       SelectedValue = lstCategories.SelectedValue;
   }
}
======================

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Steven Cheng[MSFT] - 08 Jun 2006 14:12 GMT
Hi Alex,

Does my test control helps some on this issue? If you still meet any
problem or anything else we can help, please don't hesitate to post here.

Regards,

Steven Cheng
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.