Problem in converting HTML page to user control

Last post 01-24-2008 6:32 AM by Autechrian. 7 replies.

Sort Posts:

  • Problem in converting HTML page to user control

    01-24-2008, 2:19 AM
    • Member
      10 point Member
    • om singh
    • Member since 07-27-2007, 10:35 AM
    • Posts 39
    Hello all, I have two queries related to user control. One, how can i include a .js and .css file in an .ascx page? Are we allowed to use tag, if yes then can I just include them as usual by using tag? Two, I have an HTML(not aspx) page which i want to convert to a user control. I have javascript functions being called on the "onload" and "onmousedown" event for the body of the HTML page. But since user contriol do not have body so how do I implement it...? Please help...
    Filed under:
  • Re: Problem in converting HTML page to user control

    01-24-2008, 3:37 AM
    • Member
      42 point Member
    • Autechrian
    • Member since 10-16-2007, 9:10 AM
    • Sweden
    • Posts 8
    Hello Om,

    For css in ascx, you can read a discussion here.

    JavaScript can be included with the tag, such as <script language="javascript" src="path/javascript.js" />. Or you can type the javascript code directly like this:

    <script language="javascript">
       function foobar() {
           ...
       }
    </script>
    

    I would actually prefer to rewrite the javascript for onload and onmousedown to code behind events in the ascx.cs file, giving it all the benefits of the .NET framework. If I had the time that is.

    Hope this helped, otherwise just keep asking!
    Please mark the most helpful reply/replies as "Answer"

    // Peter Hultgren, Sweden
    Microserf (my blog)
  • Re: Problem in converting HTML page to user control

    01-24-2008, 4:44 AM
    • Member
      10 point Member
    • om singh
    • Member since 07-27-2007, 10:35 AM
    • Posts 39
    Hey thanks Autechrian, so you mean to say that we can use the tag even if it is outside the tag? If it be so then I can similarly include the css file as well in the ascx page by using tag instead of including the css in the parent page as suggested on the page to which you had given the link. And as for implementing the onload and onmousedown how do we do it? actually I am little confused on this part....
  • Re: Problem in converting HTML page to user control

    01-24-2008, 4:49 AM
    • Member
      86 point Member
    • Sandhyap
    • Member since 01-23-2008, 10:12 AM
    • Posts 15

    Hi Om,

    Check this link it will help to you

    http://msdn2.microsoft.com/en-us/library/2x6sx01c.aspx

     

  • Re: Problem in converting HTML page to user control

    01-24-2008, 5:24 AM
    Answer
    • Member
      42 point Member
    • Autechrian
    • Member since 10-16-2007, 9:10 AM
    • Sweden
    • Posts 8

    You can use the <script> and <link> tags outside the <head> yes, but you need to remember that they then will affect the entire page. So if you write body{ background-color: black } in the css file that you link from the user control, then that background color will be present outside your control as well.

    So you'd be better off having your css files refered to in the main aspx page and then have special classes for your div's etc in the ascx.

    For the onload, there is a default event generated in the code-behind of your ascx file. So just open the controlname.ascx.cs and there you have a Page_Load(object sender, EventArgs e) in which you can write the code for what happens when the control loads.

    As for the onmousedown, it depends on what it does, maybe it's something that only javascript can handle. You can read more about mouse and key events here.

    Please mark the most helpful reply/replies as "Answer"

    // Peter Hultgren, Sweden
    Microserf (my blog)
  • Re: Problem in converting HTML page to user control

    01-24-2008, 5:28 AM
    • Member
      10 point Member
    • om singh
    • Member since 07-27-2007, 10:35 AM
    • Posts 39
    Thanks Sandhyap for the reply.....but I have already gone through that article now my main concern is to execute the javascript function which was being called on the events "onload" and "onmousedown" of the HTML body which I have converted to the user control. This I think can be achieved by calling the required javascript function from code behind of the user control (as suggested by "Autechrian" in his first post). But i really dont know how to do that....can you help...?
  • Re: Problem in converting HTML page to user control

    01-24-2008, 6:22 AM
    • Member
      10 point Member
    • om singh
    • Member since 07-27-2007, 10:35 AM
    • Posts 39
    Thanks Autechrian and Sandhyap I got it. Though i have to bug my head little bit but I think I will be able to manage it now.Thanks for the help.....
  • Re: Problem in converting HTML page to user control

    01-24-2008, 6:32 AM
    Answer
    • Member
      42 point Member
    • Autechrian
    • Member since 10-16-2007, 9:10 AM
    • Sweden
    • Posts 8
    No problem and good luck with your conversion to ascx.
    Please mark the most helpful reply/replies as "Answer"

    // Peter Hultgren, Sweden
    Microserf (my blog)
Page 1 of 1 (8 items)