"Collision" in DropDownLists from two instances of same UserContro

Discussion in 'ASP .Net Building Controls' started by Alex Maghen, Jun 7, 2006.

  1. Alex Maghen

    Alex Maghen Guest

    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
     
    Alex Maghen, Jun 7, 2006
    #1
    1. Advertising

  2. 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.



    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Jun 7, 2006
    #2
    1. Advertising

  3. 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.



    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Jun 8, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aaron Prohaska

    Syncronizing two instances of same control

    Aaron Prohaska, Nov 19, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    320
    Aaron Prohaska
    Nov 19, 2003
  2. Replies:
    1
    Views:
    594
    Roedy Green
    Aug 30, 2005
  3. pinguin
    Replies:
    0
    Views:
    1,090
    pinguin
    Dec 20, 2007
  4. roni

    first click wont fire on dynamic load of usercontro

    roni, Aug 6, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    140
  5. Alex Gardner

    Collision of Two Rect

    Alex Gardner, May 3, 2013, in forum: Python
    Replies:
    3
    Views:
    128
    Ian Kelly
    May 6, 2013
Loading...

Share This Page