How to pass value to usercontrol property from a datagrid

Discussion in 'ASP .Net' started by Big George, Dec 26, 2006.

  1. Big George

    Big George Guest

    Hello,

    I've got an aspx webpage with:

    - MyUserControl1 (which shows some labels)
    - A Panel containing MyUserControl1
    - DataGrid, which has a column that when is clicked fires Sub edit_

    <asp:datagrid id="MyDataGrid" runat="server" Width="100%"
    Visible="True" oneditcommand="edit_">
    ..................
    </asp:datagrid>

    </asp:panel><asp:panel id="MyPanel" runat="server">
    <uc1:myUserControl id="myUserControl1"
    runat="server"></uc1:myUserControl>
    </asp:panel>


    Protected myUserControl1 As myUserControl

    Public Sub edit_(ByVal sender As Object, ByVal e As
    DataGridCommandEventArgs)

    myUserControl1.SomeProperty = "SomeStuff"
    MyPanel.Visible = True

    End Sub


    However, when myUserControl shows up on the webpage, SomeProperty is
    null. It doesn't take the value assigned in Sub edit_
    Is there any way to assign a value to myUserontrol.SomeProperty when
    edit_ is fired?

    Because here it works:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    myUserControl1.SomeProperty = "SomeStuff" ' when myUserControl1
    shows up, SomeProperty has value "SomeStuff"
    End Sub
     
    Big George, Dec 26, 2006
    #1
    1. Advertising

  2. Could be it gets overwritten in some other event? Set breakpoints on all
    lines that set the property and see what runs when.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin


    "Big George" <> wrote in message
    news:...
    > Hello,
    >
    > I've got an aspx webpage with:
    >
    > - MyUserControl1 (which shows some labels)
    > - A Panel containing MyUserControl1
    > - DataGrid, which has a column that when is clicked fires Sub edit_
    >
    > <asp:datagrid id="MyDataGrid" runat="server" Width="100%"
    > Visible="True" oneditcommand="edit_">
    > .................
    > </asp:datagrid>
    >
    > </asp:panel><asp:panel id="MyPanel" runat="server">
    > <uc1:myUserControl id="myUserControl1"
    > runat="server"></uc1:myUserControl>
    > </asp:panel>
    >
    >
    > Protected myUserControl1 As myUserControl
    >
    > Public Sub edit_(ByVal sender As Object, ByVal e As
    > DataGridCommandEventArgs)
    >
    > myUserControl1.SomeProperty = "SomeStuff"
    > MyPanel.Visible = True
    >
    > End Sub
    >
    >
    > However, when myUserControl shows up on the webpage, SomeProperty is
    > null. It doesn't take the value assigned in Sub edit_
    > Is there any way to assign a value to myUserontrol.SomeProperty when
    > edit_ is fired?
    >
    > Because here it works:
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > myUserControl1.SomeProperty = "SomeStuff" ' when myUserControl1
    > shows up, SomeProperty has value "SomeStuff"
    > End Sub
    >
     
    Eliyahu Goldin, Dec 26, 2006
    #2
    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. Iain
    Replies:
    3
    Views:
    707
    Chris Bower
    Nov 18, 2003
  2. moid
    Replies:
    2
    Views:
    637
    John Timney \(Microsoft MVP\)
    Jan 23, 2004
  3. Mike Dole
    Replies:
    3
    Views:
    6,261
    Karl Seguin
    Nov 17, 2004
  4. Fabiano
    Replies:
    2
    Views:
    626
    =?Utf-8?B?c3Jpbmk=?=
    Jun 3, 2005
  5. Jim Ross [MVP]

    Set value of UserControl property

    Jim Ross [MVP], Sep 24, 2003, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    272
    Jacob Yang [MSFT]
    Sep 25, 2003
Loading...

Share This Page