handling events in usercontrols

Discussion in 'ASP .Net Web Controls' started by John Hopper, Jun 24, 2008.

  1. John Hopper

    John Hopper Guest

    Hello,

    I have a button in an aspx page. When that button is clicked I want to
    change a css class in a usercontrol in that page. However the button's click
    event is not raised until after the usercontrol loads, and there is no
    postback after the click event. How can I do this?

    Thank you,
     
    John Hopper, Jun 24, 2008
    #1
    1. Advertising

  2. Postback events (such as the Click event) never occur until after the Load
    event. What code are you using to change the CSS class, and what event is
    that code in?
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "John Hopper" <> wrote in message
    news:...
    > Hello,
    >
    > I have a button in an aspx page. When that button is clicked I want to
    > change a css class in a usercontrol in that page. However the button's
    > click
    > event is not raised until after the usercontrol loads, and there is no
    > postback after the click event. How can I do this?
    >
    > Thank you,
     
    Nathan Sokalski, Jun 24, 2008
    #2
    1. Advertising

  3. John Hopper

    foton Guest

    In the aspx page, in the button_click event handler, I set the cssClass of a
    button in a usercontrol contained by the aspx page. Since the event handler
    fires after the usercontrol is loaded, that doesn't work. How else to
    approach this?

    Thanks,

    "Nathan Sokalski" wrote:

    > Postback events (such as the Click event) never occur until after the Load
    > event. What code are you using to change the CSS class, and what event is
    > that code in?
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "John Hopper" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I have a button in an aspx page. When that button is clicked I want to
    > > change a css class in a usercontrol in that page. However the button's
    > > click
    > > event is not raised until after the usercontrol loads, and there is no
    > > postback after the click event. How can I do this?
    > >
    > > Thank you,

    >
    >
    >
     
    foton, Jun 24, 2008
    #3
  4. John Hopper

    foton Guest

    I can't make the change client-side because the aspx page has a master page
    and asp mangles the names of controls to keep them unique. So I've tried to
    make the change in the code-behind of the aspx page or the master page but
    the button_click event is always handled last, after all of the parts of the
    page have loaded.

    Thanks!


    "foton" wrote:

    > In the aspx page, in the button_click event handler, I set the cssClass of a
    > button in a usercontrol contained by the aspx page. Since the event handler
    > fires after the usercontrol is loaded, that doesn't work. How else to
    > approach this?
    >
    > Thanks,
    >
    > "Nathan Sokalski" wrote:
    >
    > > Postback events (such as the Click event) never occur until after the Load
    > > event. What code are you using to change the CSS class, and what event is
    > > that code in?
    > > --
    > > Nathan Sokalski
    > >
    > > http://www.nathansokalski.com/
    > >
    > > "John Hopper" <> wrote in message
    > > news:...
    > > > Hello,
    > > >
    > > > I have a button in an aspx page. When that button is clicked I want to
    > > > change a css class in a usercontrol in that page. However the button's
    > > > click
    > > > event is not raised until after the usercontrol loads, and there is no
    > > > postback after the click event. How can I do this?
    > > >
    > > > Thank you,

    > >
    > >
    > >
     
    foton, Jun 24, 2008
    #4
  5. John Hopper

    Evan Freeman Guest

    One it doesn't mangle the name per say. You could easily expose the
    generated name to your client side script.

    <asp:Button ID="MyControl" runat="server" Text="Foo"/>

    var control = <%MyControl.ClientId %>;
    document.getElementById(control).cssCLass = "CoolBeans";

    Second why would you want to change the style before the elements are
    loaded, you'd just spit out errors, the dom needs to be ready befor eyou
    start manipulation of tags. Anyhow the above should let you do what you need
    client side. It's not perfect I typed it from memory.

    Enjoy!





    --
    Evan Freeman

    http://evanfreeman.blogspot.com
    "foton" <> wrote in message
    news:...
    >I can't make the change client-side because the aspx page has a master page
    > and asp mangles the names of controls to keep them unique. So I've tried
    > to
    > make the change in the code-behind of the aspx page or the master page but
    > the button_click event is always handled last, after all of the parts of
    > the
    > page have loaded.
    >
    > Thanks!
    >
    >
    > "foton" wrote:
    >
    >> In the aspx page, in the button_click event handler, I set the cssClass
    >> of a
    >> button in a usercontrol contained by the aspx page. Since the event
    >> handler
    >> fires after the usercontrol is loaded, that doesn't work. How else to
    >> approach this?
    >>
    >> Thanks,
    >>
    >> "Nathan Sokalski" wrote:
    >>
    >> > Postback events (such as the Click event) never occur until after the
    >> > Load
    >> > event. What code are you using to change the CSS class, and what event
    >> > is
    >> > that code in?
    >> > --
    >> > Nathan Sokalski
    >> >
    >> > http://www.nathansokalski.com/
    >> >
    >> > "John Hopper" <> wrote in message
    >> > news:...
    >> > > Hello,
    >> > >
    >> > > I have a button in an aspx page. When that button is clicked I want
    >> > > to
    >> > > change a css class in a usercontrol in that page. However the
    >> > > button's
    >> > > click
    >> > > event is not raised until after the usercontrol loads, and there is
    >> > > no
    >> > > postback after the click event. How can I do this?
    >> > >
    >> > > Thank you,
    >> >
    >> >
    >> >
     
    Evan Freeman, Jun 24, 2008
    #5
  6. John Hopper

    foton Guest

    I'm sorry that my question isn't clear. I have an aspx page which uses a
    master page. In that aspx page I have 9 instances of the same usercontrol. I
    have other pages with different numbers of this usercontrol. Each usercontrol
    has a button named "btnEdit". When a 'preview" button is clicked in the aspx
    page I need to hide the btnEdit buttons. Each will have a unique id thanks to
    asp's efforts to keep them unique. The "preview" button's click event fires
    in the aspx page's codebehind AFTER the 9 usercontrols and their edit buttons
    have loaded. So what would be a way to change the cssClass of each of the
    usercontrol's btnEdit buttons as a result of the "preview" button being
    clicked in the containing aspx page?

    Thank you,

    "Evan Freeman" wrote:

    > One it doesn't mangle the name per say. You could easily expose the
    > generated name to your client side script.
    >
    > <asp:Button ID="MyControl" runat="server" Text="Foo"/>
    >
    > var control = <%MyControl.ClientId %>;
    > document.getElementById(control).cssCLass = "CoolBeans";
    >
    > Second why would you want to change the style before the elements are
    > loaded, you'd just spit out errors, the dom needs to be ready befor eyou
    > start manipulation of tags. Anyhow the above should let you do what you need
    > client side. It's not perfect I typed it from memory.
    >
    > Enjoy!
    >
    >
    >
    >
    >
    > --
    > Evan Freeman
    >
    > http://evanfreeman.blogspot.com
    > "foton" <> wrote in message
    > news:...
    > >I can't make the change client-side because the aspx page has a master page
    > > and asp mangles the names of controls to keep them unique. So I've tried
    > > to
    > > make the change in the code-behind of the aspx page or the master page but
    > > the button_click event is always handled last, after all of the parts of
    > > the
    > > page have loaded.
    > >
    > > Thanks!
    > >
    > >
    > > "foton" wrote:
    > >
    > >> In the aspx page, in the button_click event handler, I set the cssClass
    > >> of a
    > >> button in a usercontrol contained by the aspx page. Since the event
    > >> handler
    > >> fires after the usercontrol is loaded, that doesn't work. How else to
    > >> approach this?
    > >>
    > >> Thanks,
    > >>
    > >> "Nathan Sokalski" wrote:
    > >>
    > >> > Postback events (such as the Click event) never occur until after the
    > >> > Load
    > >> > event. What code are you using to change the CSS class, and what event
    > >> > is
    > >> > that code in?
    > >> > --
    > >> > Nathan Sokalski
    > >> >
    > >> > http://www.nathansokalski.com/
    > >> >
    > >> > "John Hopper" <> wrote in message
    > >> > news:...
    > >> > > Hello,
    > >> > >
    > >> > > I have a button in an aspx page. When that button is clicked I want
    > >> > > to
    > >> > > change a css class in a usercontrol in that page. However the
    > >> > > button's
    > >> > > click
    > >> > > event is not raised until after the usercontrol loads, and there is
    > >> > > no
    > >> > > postback after the click event. How can I do this?
    > >> > >
    > >> > > Thank you,
    > >> >
    > >> >
    > >> >

    >
    >
    >
     
    foton, Jun 24, 2008
    #6
  7. John Hopper

    Evan Freeman Guest

    Are these controls dynamically created?

    Anyhow the method I told you should work, just expose all the generated id's
    as an array, and then loop through. I mean you are specifying an ID of some
    kind in the markup, if not then you need to rethink what your doing.

    Another way to do it would be to expose an event handler in your control and
    make them all listen to the click event of the preview button, then do your
    CssChanging from with in that.

    --
    Evan Freeman

    http://evanfreeman.blogspot.com
    "foton" <> wrote in message
    news:...
    > I'm sorry that my question isn't clear. I have an aspx page which uses a
    > master page. In that aspx page I have 9 instances of the same usercontrol.
    > I
    > have other pages with different numbers of this usercontrol. Each
    > usercontrol
    > has a button named "btnEdit". When a 'preview" button is clicked in the
    > aspx
    > page I need to hide the btnEdit buttons. Each will have a unique id thanks
    > to
    > asp's efforts to keep them unique. The "preview" button's click event
    > fires
    > in the aspx page's codebehind AFTER the 9 usercontrols and their edit
    > buttons
    > have loaded. So what would be a way to change the cssClass of each of the
    > usercontrol's btnEdit buttons as a result of the "preview" button being
    > clicked in the containing aspx page?
    >
    > Thank you,
    >
    > "Evan Freeman" wrote:
    >
    >> One it doesn't mangle the name per say. You could easily expose the
    >> generated name to your client side script.
    >>
    >> <asp:Button ID="MyControl" runat="server" Text="Foo"/>
    >>
    >> var control = <%MyControl.ClientId %>;
    >> document.getElementById(control).cssCLass = "CoolBeans";
    >>
    >> Second why would you want to change the style before the elements are
    >> loaded, you'd just spit out errors, the dom needs to be ready befor eyou
    >> start manipulation of tags. Anyhow the above should let you do what you
    >> need
    >> client side. It's not perfect I typed it from memory.
    >>
    >> Enjoy!
    >>
    >>
    >>
    >>
    >>
    >> --
    >> Evan Freeman
    >>
    >> http://evanfreeman.blogspot.com
    >> "foton" <> wrote in message
    >> news:...
    >> >I can't make the change client-side because the aspx page has a master
    >> >page
    >> > and asp mangles the names of controls to keep them unique. So I've
    >> > tried
    >> > to
    >> > make the change in the code-behind of the aspx page or the master page
    >> > but
    >> > the button_click event is always handled last, after all of the parts
    >> > of
    >> > the
    >> > page have loaded.
    >> >
    >> > Thanks!
    >> >
    >> >
    >> > "foton" wrote:
    >> >
    >> >> In the aspx page, in the button_click event handler, I set the
    >> >> cssClass
    >> >> of a
    >> >> button in a usercontrol contained by the aspx page. Since the event
    >> >> handler
    >> >> fires after the usercontrol is loaded, that doesn't work. How else to
    >> >> approach this?
    >> >>
    >> >> Thanks,
    >> >>
    >> >> "Nathan Sokalski" wrote:
    >> >>
    >> >> > Postback events (such as the Click event) never occur until after
    >> >> > the
    >> >> > Load
    >> >> > event. What code are you using to change the CSS class, and what
    >> >> > event
    >> >> > is
    >> >> > that code in?
    >> >> > --
    >> >> > Nathan Sokalski
    >> >> >
    >> >> > http://www.nathansokalski.com/
    >> >> >
    >> >> > "John Hopper" <> wrote in message
    >> >> > news:...
    >> >> > > Hello,
    >> >> > >
    >> >> > > I have a button in an aspx page. When that button is clicked I
    >> >> > > want
    >> >> > > to
    >> >> > > change a css class in a usercontrol in that page. However the
    >> >> > > button's
    >> >> > > click
    >> >> > > event is not raised until after the usercontrol loads, and there
    >> >> > > is
    >> >> > > no
    >> >> > > postback after the click event. How can I do this?
    >> >> > >
    >> >> > > Thank you,
    >> >> >
    >> >> >
    >> >> >

    >>
    >>
    >>
     
    Evan Freeman, Jun 24, 2008
    #7
  8. John Hopper

    foton Guest

    Evan,

    Thanks for your advice! How do I make the usercontrols event handler listen
    for the containing page's button click event? Would it be something like ...
    handles me.parent.page.findControl("btnPreview")_click() or something like
    that?

    "Evan Freeman" wrote:

    > Are these controls dynamically created?
    >
    > Anyhow the method I told you should work, just expose all the generated id's
    > as an array, and then loop through. I mean you are specifying an ID of some
    > kind in the markup, if not then you need to rethink what your doing.
    >
    > Another way to do it would be to expose an event handler in your control and
    > make them all listen to the click event of the preview button, then do your
    > CssChanging from with in that.
    >
    > --
    > Evan Freeman
    >
    > http://evanfreeman.blogspot.com
    > "foton" <> wrote in message
    > news:...
    > > I'm sorry that my question isn't clear. I have an aspx page which uses a
    > > master page. In that aspx page I have 9 instances of the same usercontrol.
    > > I
    > > have other pages with different numbers of this usercontrol. Each
    > > usercontrol
    > > has a button named "btnEdit". When a 'preview" button is clicked in the
    > > aspx
    > > page I need to hide the btnEdit buttons. Each will have a unique id thanks
    > > to
    > > asp's efforts to keep them unique. The "preview" button's click event
    > > fires
    > > in the aspx page's codebehind AFTER the 9 usercontrols and their edit
    > > buttons
    > > have loaded. So what would be a way to change the cssClass of each of the
    > > usercontrol's btnEdit buttons as a result of the "preview" button being
    > > clicked in the containing aspx page?
    > >
    > > Thank you,
    > >
    > > "Evan Freeman" wrote:
    > >
    > >> One it doesn't mangle the name per say. You could easily expose the
    > >> generated name to your client side script.
    > >>
    > >> <asp:Button ID="MyControl" runat="server" Text="Foo"/>
    > >>
    > >> var control = <%MyControl.ClientId %>;
    > >> document.getElementById(control).cssCLass = "CoolBeans";
    > >>
    > >> Second why would you want to change the style before the elements are
    > >> loaded, you'd just spit out errors, the dom needs to be ready befor eyou
    > >> start manipulation of tags. Anyhow the above should let you do what you
    > >> need
    > >> client side. It's not perfect I typed it from memory.
    > >>
    > >> Enjoy!
    > >>
    > >>
    > >>
    > >>
    > >>
    > >> --
    > >> Evan Freeman
    > >>
    > >> http://evanfreeman.blogspot.com
    > >> "foton" <> wrote in message
    > >> news:...
    > >> >I can't make the change client-side because the aspx page has a master
    > >> >page
    > >> > and asp mangles the names of controls to keep them unique. So I've
    > >> > tried
    > >> > to
    > >> > make the change in the code-behind of the aspx page or the master page
    > >> > but
    > >> > the button_click event is always handled last, after all of the parts
    > >> > of
    > >> > the
    > >> > page have loaded.
    > >> >
    > >> > Thanks!
    > >> >
    > >> >
    > >> > "foton" wrote:
    > >> >
    > >> >> In the aspx page, in the button_click event handler, I set the
    > >> >> cssClass
    > >> >> of a
    > >> >> button in a usercontrol contained by the aspx page. Since the event
    > >> >> handler
    > >> >> fires after the usercontrol is loaded, that doesn't work. How else to
    > >> >> approach this?
    > >> >>
    > >> >> Thanks,
    > >> >>
    > >> >> "Nathan Sokalski" wrote:
    > >> >>
    > >> >> > Postback events (such as the Click event) never occur until after
    > >> >> > the
    > >> >> > Load
    > >> >> > event. What code are you using to change the CSS class, and what
    > >> >> > event
    > >> >> > is
    > >> >> > that code in?
    > >> >> > --
    > >> >> > Nathan Sokalski
    > >> >> >
    > >> >> > http://www.nathansokalski.com/
    > >> >> >
    > >> >> > "John Hopper" <> wrote in message
    > >> >> > news:...
    > >> >> > > Hello,
    > >> >> > >
    > >> >> > > I have a button in an aspx page. When that button is clicked I
    > >> >> > > want
    > >> >> > > to
    > >> >> > > change a css class in a usercontrol in that page. However the
    > >> >> > > button's
    > >> >> > > click
    > >> >> > > event is not raised until after the usercontrol loads, and there
    > >> >> > > is
    > >> >> > > no
    > >> >> > > postback after the click event. How can I do this?
    > >> >> > >
    > >> >> > > Thank you,
    > >> >> >
    > >> >> >
    > >> >> >
    > >>
    > >>
    > >>

    >
    >
    >
     
    foton, Jun 24, 2008
    #8
  9. John Hopper

    Evan Freeman Guest

    Button1.Click += new
    System.EventHandler(MyWierdUserControl1.myEventHandler);Button1.Click += new
    System.EventHandler(MyWierdUserControl2.myEventHandler);Button1.Click += new
    System.EventHandler(MyWierdUserControl3.myEventHandler);
    --
    Evan Freeman

    http://evanfreeman.blogspot.com
    "foton" <> wrote in message
    news:...
    > Evan,
    >
    > Thanks for your advice! How do I make the usercontrols event handler
    > listen
    > for the containing page's button click event? Would it be something like
    > ...
    > handles me.parent.page.findControl("btnPreview")_click() or something like
    > that?
    >
    > "Evan Freeman" wrote:
    >
    >> Are these controls dynamically created?
    >>
    >> Anyhow the method I told you should work, just expose all the generated
    >> id's
    >> as an array, and then loop through. I mean you are specifying an ID of
    >> some
    >> kind in the markup, if not then you need to rethink what your doing.
    >>
    >> Another way to do it would be to expose an event handler in your control
    >> and
    >> make them all listen to the click event of the preview button, then do
    >> your
    >> CssChanging from with in that.
    >>
    >> --
    >> Evan Freeman
    >>
    >> http://evanfreeman.blogspot.com
    >> "foton" <> wrote in message
    >> news:...
    >> > I'm sorry that my question isn't clear. I have an aspx page which uses
    >> > a
    >> > master page. In that aspx page I have 9 instances of the same
    >> > usercontrol.
    >> > I
    >> > have other pages with different numbers of this usercontrol. Each
    >> > usercontrol
    >> > has a button named "btnEdit". When a 'preview" button is clicked in the
    >> > aspx
    >> > page I need to hide the btnEdit buttons. Each will have a unique id
    >> > thanks
    >> > to
    >> > asp's efforts to keep them unique. The "preview" button's click event
    >> > fires
    >> > in the aspx page's codebehind AFTER the 9 usercontrols and their edit
    >> > buttons
    >> > have loaded. So what would be a way to change the cssClass of each of
    >> > the
    >> > usercontrol's btnEdit buttons as a result of the "preview" button being
    >> > clicked in the containing aspx page?
    >> >
    >> > Thank you,
    >> >
    >> > "Evan Freeman" wrote:
    >> >
    >> >> One it doesn't mangle the name per say. You could easily expose the
    >> >> generated name to your client side script.
    >> >>
    >> >> <asp:Button ID="MyControl" runat="server" Text="Foo"/>
    >> >>
    >> >> var control = <%MyControl.ClientId %>;
    >> >> document.getElementById(control).cssCLass = "CoolBeans";
    >> >>
    >> >> Second why would you want to change the style before the elements are
    >> >> loaded, you'd just spit out errors, the dom needs to be ready befor
    >> >> eyou
    >> >> start manipulation of tags. Anyhow the above should let you do what
    >> >> you
    >> >> need
    >> >> client side. It's not perfect I typed it from memory.
    >> >>
    >> >> Enjoy!
    >> >>
    >> >>
    >> >>
    >> >>
    >> >>
    >> >> --
    >> >> Evan Freeman
    >> >>
    >> >> http://evanfreeman.blogspot.com
    >> >> "foton" <> wrote in message
    >> >> news:...
    >> >> >I can't make the change client-side because the aspx page has a
    >> >> >master
    >> >> >page
    >> >> > and asp mangles the names of controls to keep them unique. So I've
    >> >> > tried
    >> >> > to
    >> >> > make the change in the code-behind of the aspx page or the master
    >> >> > page
    >> >> > but
    >> >> > the button_click event is always handled last, after all of the
    >> >> > parts
    >> >> > of
    >> >> > the
    >> >> > page have loaded.
    >> >> >
    >> >> > Thanks!
    >> >> >
    >> >> >
    >> >> > "foton" wrote:
    >> >> >
    >> >> >> In the aspx page, in the button_click event handler, I set the
    >> >> >> cssClass
    >> >> >> of a
    >> >> >> button in a usercontrol contained by the aspx page. Since the event
    >> >> >> handler
    >> >> >> fires after the usercontrol is loaded, that doesn't work. How else
    >> >> >> to
    >> >> >> approach this?
    >> >> >>
    >> >> >> Thanks,
    >> >> >>
    >> >> >> "Nathan Sokalski" wrote:
    >> >> >>
    >> >> >> > Postback events (such as the Click event) never occur until after
    >> >> >> > the
    >> >> >> > Load
    >> >> >> > event. What code are you using to change the CSS class, and what
    >> >> >> > event
    >> >> >> > is
    >> >> >> > that code in?
    >> >> >> > --
    >> >> >> > Nathan Sokalski
    >> >> >> >
    >> >> >> > http://www.nathansokalski.com/
    >> >> >> >
    >> >> >> > "John Hopper" <> wrote in message
    >> >> >> > news:...
    >> >> >> > > Hello,
    >> >> >> > >
    >> >> >> > > I have a button in an aspx page. When that button is clicked I
    >> >> >> > > want
    >> >> >> > > to
    >> >> >> > > change a css class in a usercontrol in that page. However the
    >> >> >> > > button's
    >> >> >> > > click
    >> >> >> > > event is not raised until after the usercontrol loads, and
    >> >> >> > > there
    >> >> >> > > is
    >> >> >> > > no
    >> >> >> > > postback after the click event. How can I do this?
    >> >> >> > >
    >> >> >> > > Thank you,
    >> >> >> >
    >> >> >> >
    >> >> >> >
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
     
    Evan Freeman, Jun 24, 2008
    #9
  10. John Hopper

    foton Guest

    Thanks. It's weird not wierd. Actually it's not even weird. It's just
    reusable. :)

    "Evan Freeman" wrote:

    > Button1.Click += new
    > System.EventHandler(MyWierdUserControl1.myEventHandler);Button1.Click += new
    > System.EventHandler(MyWierdUserControl2.myEventHandler);Button1.Click += new
    > System.EventHandler(MyWierdUserControl3.myEventHandler);
    > --
    > Evan Freeman
    >
    > http://evanfreeman.blogspot.com
    > "foton" <> wrote in message
    > news:...
    > > Evan,
    > >
    > > Thanks for your advice! How do I make the usercontrols event handler
    > > listen
    > > for the containing page's button click event? Would it be something like
    > > ...
    > > handles me.parent.page.findControl("btnPreview")_click() or something like
    > > that?
    > >
    > > "Evan Freeman" wrote:
    > >
    > >> Are these controls dynamically created?
    > >>
    > >> Anyhow the method I told you should work, just expose all the generated
    > >> id's
    > >> as an array, and then loop through. I mean you are specifying an ID of
    > >> some
    > >> kind in the markup, if not then you need to rethink what your doing.
    > >>
    > >> Another way to do it would be to expose an event handler in your control
    > >> and
    > >> make them all listen to the click event of the preview button, then do
    > >> your
    > >> CssChanging from with in that.
    > >>
    > >> --
    > >> Evan Freeman
    > >>
    > >> http://evanfreeman.blogspot.com
    > >> "foton" <> wrote in message
    > >> news:...
    > >> > I'm sorry that my question isn't clear. I have an aspx page which uses
    > >> > a
    > >> > master page. In that aspx page I have 9 instances of the same
    > >> > usercontrol.
    > >> > I
    > >> > have other pages with different numbers of this usercontrol. Each
    > >> > usercontrol
    > >> > has a button named "btnEdit". When a 'preview" button is clicked in the
    > >> > aspx
    > >> > page I need to hide the btnEdit buttons. Each will have a unique id
    > >> > thanks
    > >> > to
    > >> > asp's efforts to keep them unique. The "preview" button's click event
    > >> > fires
    > >> > in the aspx page's codebehind AFTER the 9 usercontrols and their edit
    > >> > buttons
    > >> > have loaded. So what would be a way to change the cssClass of each of
    > >> > the
    > >> > usercontrol's btnEdit buttons as a result of the "preview" button being
    > >> > clicked in the containing aspx page?
    > >> >
    > >> > Thank you,
    > >> >
    > >> > "Evan Freeman" wrote:
    > >> >
    > >> >> One it doesn't mangle the name per say. You could easily expose the
    > >> >> generated name to your client side script.
    > >> >>
    > >> >> <asp:Button ID="MyControl" runat="server" Text="Foo"/>
    > >> >>
    > >> >> var control = <%MyControl.ClientId %>;
    > >> >> document.getElementById(control).cssCLass = "CoolBeans";
    > >> >>
    > >> >> Second why would you want to change the style before the elements are
    > >> >> loaded, you'd just spit out errors, the dom needs to be ready befor
    > >> >> eyou
    > >> >> start manipulation of tags. Anyhow the above should let you do what
    > >> >> you
    > >> >> need
    > >> >> client side. It's not perfect I typed it from memory.
    > >> >>
    > >> >> Enjoy!
    > >> >>
    > >> >>
    > >> >>
    > >> >>
    > >> >>
    > >> >> --
    > >> >> Evan Freeman
    > >> >>
    > >> >> http://evanfreeman.blogspot.com
    > >> >> "foton" <> wrote in message
    > >> >> news:...
    > >> >> >I can't make the change client-side because the aspx page has a
    > >> >> >master
    > >> >> >page
    > >> >> > and asp mangles the names of controls to keep them unique. So I've
    > >> >> > tried
    > >> >> > to
    > >> >> > make the change in the code-behind of the aspx page or the master
    > >> >> > page
    > >> >> > but
    > >> >> > the button_click event is always handled last, after all of the
    > >> >> > parts
    > >> >> > of
    > >> >> > the
    > >> >> > page have loaded.
    > >> >> >
    > >> >> > Thanks!
    > >> >> >
    > >> >> >
    > >> >> > "foton" wrote:
    > >> >> >
    > >> >> >> In the aspx page, in the button_click event handler, I set the
    > >> >> >> cssClass
    > >> >> >> of a
    > >> >> >> button in a usercontrol contained by the aspx page. Since the event
    > >> >> >> handler
    > >> >> >> fires after the usercontrol is loaded, that doesn't work. How else
    > >> >> >> to
    > >> >> >> approach this?
    > >> >> >>
    > >> >> >> Thanks,
    > >> >> >>
    > >> >> >> "Nathan Sokalski" wrote:
    > >> >> >>
    > >> >> >> > Postback events (such as the Click event) never occur until after
    > >> >> >> > the
    > >> >> >> > Load
    > >> >> >> > event. What code are you using to change the CSS class, and what
    > >> >> >> > event
    > >> >> >> > is
    > >> >> >> > that code in?
    > >> >> >> > --
    > >> >> >> > Nathan Sokalski
    > >> >> >> >
    > >> >> >> > http://www.nathansokalski.com/
    > >> >> >> >
    > >> >> >> > "John Hopper" <> wrote in message
    > >> >> >> > news:...
    > >> >> >> > > Hello,
    > >> >> >> > >
    > >> >> >> > > I have a button in an aspx page. When that button is clicked I
    > >> >> >> > > want
    > >> >> >> > > to
    > >> >> >> > > change a css class in a usercontrol in that page. However the
    > >> >> >> > > button's
    > >> >> >> > > click
    > >> >> >> > > event is not raised until after the usercontrol loads, and
    > >> >> >> > > there
    > >> >> >> > > is
    > >> >> >> > > no
    > >> >> >> > > postback after the click event. How can I do this?
    > >> >> >> > >
    > >> >> >> > > Thank you,
    > >> >> >> >
    > >> >> >> >
    > >> >> >> >
    > >> >>
    > >> >>
    > >> >>
    > >>
    > >>
    > >>

    >
    >
    >
     
    foton, Jun 24, 2008
    #10
  11. John Hopper

    Evan Freeman Guest

    lol I meant "Wired" not weird but that works to lol.

    --
    Evan Freeman

    http://evanfreeman.blogspot.com
    "foton" <> wrote in message
    news:...
    > Thanks. It's weird not wierd. Actually it's not even weird. It's just
    > reusable. :)
    >
    > "Evan Freeman" wrote:
    >
    >> Button1.Click += new
    >> System.EventHandler(MyWierdUserControl1.myEventHandler);Button1.Click +=
    >> new
    >> System.EventHandler(MyWierdUserControl2.myEventHandler);Button1.Click +=
    >> new
    >> System.EventHandler(MyWierdUserControl3.myEventHandler);
    >> --
    >> Evan Freeman
    >>
    >> http://evanfreeman.blogspot.com
    >> "foton" <> wrote in message
    >> news:...
    >> > Evan,
    >> >
    >> > Thanks for your advice! How do I make the usercontrols event handler
    >> > listen
    >> > for the containing page's button click event? Would it be something
    >> > like
    >> > ...
    >> > handles me.parent.page.findControl("btnPreview")_click() or something
    >> > like
    >> > that?
    >> >
    >> > "Evan Freeman" wrote:
    >> >
    >> >> Are these controls dynamically created?
    >> >>
    >> >> Anyhow the method I told you should work, just expose all the
    >> >> generated
    >> >> id's
    >> >> as an array, and then loop through. I mean you are specifying an ID of
    >> >> some
    >> >> kind in the markup, if not then you need to rethink what your doing.
    >> >>
    >> >> Another way to do it would be to expose an event handler in your
    >> >> control
    >> >> and
    >> >> make them all listen to the click event of the preview button, then do
    >> >> your
    >> >> CssChanging from with in that.
    >> >>
    >> >> --
    >> >> Evan Freeman
    >> >>
    >> >> http://evanfreeman.blogspot.com
    >> >> "foton" <> wrote in message
    >> >> news:...
    >> >> > I'm sorry that my question isn't clear. I have an aspx page which
    >> >> > uses
    >> >> > a
    >> >> > master page. In that aspx page I have 9 instances of the same
    >> >> > usercontrol.
    >> >> > I
    >> >> > have other pages with different numbers of this usercontrol. Each
    >> >> > usercontrol
    >> >> > has a button named "btnEdit". When a 'preview" button is clicked in
    >> >> > the
    >> >> > aspx
    >> >> > page I need to hide the btnEdit buttons. Each will have a unique id
    >> >> > thanks
    >> >> > to
    >> >> > asp's efforts to keep them unique. The "preview" button's click
    >> >> > event
    >> >> > fires
    >> >> > in the aspx page's codebehind AFTER the 9 usercontrols and their
    >> >> > edit
    >> >> > buttons
    >> >> > have loaded. So what would be a way to change the cssClass of each
    >> >> > of
    >> >> > the
    >> >> > usercontrol's btnEdit buttons as a result of the "preview" button
    >> >> > being
    >> >> > clicked in the containing aspx page?
    >> >> >
    >> >> > Thank you,
    >> >> >
    >> >> > "Evan Freeman" wrote:
    >> >> >
    >> >> >> One it doesn't mangle the name per say. You could easily expose the
    >> >> >> generated name to your client side script.
    >> >> >>
    >> >> >> <asp:Button ID="MyControl" runat="server" Text="Foo"/>
    >> >> >>
    >> >> >> var control = <%MyControl.ClientId %>;
    >> >> >> document.getElementById(control).cssCLass = "CoolBeans";
    >> >> >>
    >> >> >> Second why would you want to change the style before the elements
    >> >> >> are
    >> >> >> loaded, you'd just spit out errors, the dom needs to be ready befor
    >> >> >> eyou
    >> >> >> start manipulation of tags. Anyhow the above should let you do what
    >> >> >> you
    >> >> >> need
    >> >> >> client side. It's not perfect I typed it from memory.
    >> >> >>
    >> >> >> Enjoy!
    >> >> >>
    >> >> >>
    >> >> >>
    >> >> >>
    >> >> >>
    >> >> >> --
    >> >> >> Evan Freeman
    >> >> >>
    >> >> >> http://evanfreeman.blogspot.com
    >> >> >> "foton" <> wrote in message
    >> >> >> news:...
    >> >> >> >I can't make the change client-side because the aspx page has a
    >> >> >> >master
    >> >> >> >page
    >> >> >> > and asp mangles the names of controls to keep them unique. So
    >> >> >> > I've
    >> >> >> > tried
    >> >> >> > to
    >> >> >> > make the change in the code-behind of the aspx page or the master
    >> >> >> > page
    >> >> >> > but
    >> >> >> > the button_click event is always handled last, after all of the
    >> >> >> > parts
    >> >> >> > of
    >> >> >> > the
    >> >> >> > page have loaded.
    >> >> >> >
    >> >> >> > Thanks!
    >> >> >> >
    >> >> >> >
    >> >> >> > "foton" wrote:
    >> >> >> >
    >> >> >> >> In the aspx page, in the button_click event handler, I set the
    >> >> >> >> cssClass
    >> >> >> >> of a
    >> >> >> >> button in a usercontrol contained by the aspx page. Since the
    >> >> >> >> event
    >> >> >> >> handler
    >> >> >> >> fires after the usercontrol is loaded, that doesn't work. How
    >> >> >> >> else
    >> >> >> >> to
    >> >> >> >> approach this?
    >> >> >> >>
    >> >> >> >> Thanks,
    >> >> >> >>
    >> >> >> >> "Nathan Sokalski" wrote:
    >> >> >> >>
    >> >> >> >> > Postback events (such as the Click event) never occur until
    >> >> >> >> > after
    >> >> >> >> > the
    >> >> >> >> > Load
    >> >> >> >> > event. What code are you using to change the CSS class, and
    >> >> >> >> > what
    >> >> >> >> > event
    >> >> >> >> > is
    >> >> >> >> > that code in?
    >> >> >> >> > --
    >> >> >> >> > Nathan Sokalski
    >> >> >> >> >
    >> >> >> >> > http://www.nathansokalski.com/
    >> >> >> >> >
    >> >> >> >> > "John Hopper" <> wrote in
    >> >> >> >> > message
    >> >> >> >> > news:...
    >> >> >> >> > > Hello,
    >> >> >> >> > >
    >> >> >> >> > > I have a button in an aspx page. When that button is clicked
    >> >> >> >> > > I
    >> >> >> >> > > want
    >> >> >> >> > > to
    >> >> >> >> > > change a css class in a usercontrol in that page. However
    >> >> >> >> > > the
    >> >> >> >> > > button's
    >> >> >> >> > > click
    >> >> >> >> > > event is not raised until after the usercontrol loads, and
    >> >> >> >> > > there
    >> >> >> >> > > is
    >> >> >> >> > > no
    >> >> >> >> > > postback after the click event. How can I do this?
    >> >> >> >> > >
    >> >> >> >> > > Thank you,
    >> >> >> >> >
    >> >> >> >> >
    >> >> >> >> >
    >> >> >>
    >> >> >>
    >> >> >>
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
     
    Evan Freeman, Jun 24, 2008
    #11
    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. Nathan Sokalski

    Order of events, databinding, and UserControls

    Nathan Sokalski, May 21, 2006, in forum: ASP .Net
    Replies:
    9
    Views:
    462
    Nathan Sokalski
    May 23, 2006
  2. seigo
    Replies:
    0
    Views:
    508
    seigo
    Aug 20, 2006
  3. Ibana
    Replies:
    0
    Views:
    333
    Ibana
    Oct 3, 2006
  4. JacekDr
    Replies:
    3
    Views:
    1,091
    Muhammad Naveed Yaseen
    Aug 26, 2007
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    374
    Chris
    Aug 30, 2005
Loading...

Share This Page