Tech Off Thread

6 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Question with Client side events and ASP.NET

Back to Forum: Tech Off
  • User profile image
    MisterDonut

    Howdy.. 

    I am a pretty good winform developer, but a minimal webform developer. I was hoping someone might be able to lend a hand..

    If I have a CheckBoxList control and want to make it disappear when the mouse leaves, how do I accomplish this in client side code? The issue I see is that CheckBoxList is runs on the server, and it's not clear to me how to accomplish this being invisible.

    I'd be even happier if I could get this to PostBack when the mouse leave occurs...

    Any help would be really appreciated!

  • User profile image
    W3bbo

    Impossible Smiley

    Y'see, this is why I dislike ASP.NET's "Event" model, which seems inappropriate for a stateless medium, like HTTP.

    You'll need to do it with client-side Javascript/ECMAScript I'm afraid.

  • User profile image
    Harlequin

    Just have a javascript function run on the checkboxlists omouseout event.

    function MyMouseOut()
    {
       __doPostBack('YourCheckBoxListObjectNameHere','');
    }

  • User profile image
    MisterDonut

    But, how is a good way to actually handle that event? I somehow need to wire the "MyMouseOut()" to the CheckBoxControl's OnMouseOut event. Doesn't that actually have to be declared the control's description itself? Or is there a JavaScript equivalent to "Handles CheckBoxControl1.OnMouse" in VB.NET?


  • User profile image
    Sven Groot

    MisterDonut wrote:

    But, how is a good way to actually handle that event? I somehow need to wire the "MyMouseOut()" to the CheckBoxControl's OnMouseOut event. Doesn't that actually have to be declared the control's description itself? Or is there a JavaScript equivalent to "Handles CheckBoxControl1.OnMouse" in VB.NET?



    You can just put <asp:CheckBox id="mycheckbox" Text="My checkbox" onmouseout="MyMouseOut()" Runat="server" />

    The VS.NET editor will complain onmouseout is not a supported attribute, but ignore it. ASP.NET will generate the following client side HTML for this code:
    <span onmouseout="MyMouseOut()"><input id="mycheckbox" type="checkbox" name="mycheckbox" /><label for="mycheckbox">My checkbox</label></span>

  • User profile image
    MisterDonut

    Thanks, Sven. I just figured out the same thing, albeit differently. I put it in the PageLoad() and add the attribute on the server side. No compiliation errors or warnings. 

    Thanks, all.
     

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.