Ajax on Web Application converted from 2003 to 2008

Last post 07-24-2008 11:16 AM by EnterTheUser. 11 replies.

Sort Posts:

  • Ajax on Web Application converted from 2003 to 2008

    07-22-2008, 12:06 PM

     Hi All,

     I have a web application that was recently converted from Visual studio 2003 to 2008.  I am now trying to add some Ajax functionality to one of the pages, but the ajax doesn't appear to be working.  Before I began I made the necessary changes to my web.config file and added that Ajax extensions to my toolkit.  To give it a test, I copied some ajax code from one of the tutorials on this site (this one http://www.asp.net/learn/ajax-videos/video-85.aspx), but instead of doing what it's supposed to, which is displaying a Panel to allow the user to change the paragraph style when an asp link is clicked, it just reloads the page.  I tested the exact code in a new empty project and it seems to work fine from there.

     Does anyone have any ideas what I may be missing besides the changes to the web.config file?

     Any help is appreciated, and if you need more information let me know.
     

  • Re: Ajax on Web Application converted from 2003 to 2008

    07-22-2008, 12:30 PM
    • Loading...
    • bmains
    • Joined on 10-22-2004, 12:20 PM
    • Posts 5,070

    Hey,

    Make sure a ScriptManager is added; what does the page look like?

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: Ajax on Web Application converted from 2003 to 2008

    07-22-2008, 12:45 PM

    Thanks for the quick reply.  I've got the script manager in there.  The page is just a copy of the sample I mentioned above, the HTML code is this:

    <head runat="server">
        <title>Untitled Page</title>
        <link href="Styles.css" type="text/css" rel="stylesheet" />
        <script type="text/javascript">
       
          function pageLoad() {
          }
       
        </script>
            <script type="text/javascript">
        var styleToSelect;
        function onOk() {
        document.getElementById('Paragraph1').className = styleToSelect;
        }
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            <asp:PlaceHolder ID="phDetail" runat="server"></asp:PlaceHolder>
        </div>
        <asp:LinkButton ID="LinkButton1" runat="server">Please click to select an alternate text style.</asp:LinkButton><br />
    <br />
    <div>
       <p id="Paragraph1">
         <a href="http://joeon.net"><span style="color: #3366cc">Joe Stagner</span></a>,
          Some text.
       </p>
       <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none" Width="233px">
       <p>Choose the style you would like:</p>
       <input id="RadioA" name="Radio" onclick="styleToSelect = 'sampleStyleA';" type="radio" />
       <label class="sampleStyleA" for="RadioA">Choose THIS Style.</label><br />
       <input id="RadioB" name="Radio" onclick="styleToSelect = 'sampleStyleB';" type="radio" />
       <label class="sampleStyleB" for="RadioB">Choose THIS Style.</label><br />
       <input id="RadioC" name="Radio" onclick="styleToSelect = 'sampleStyleC';" type="radio" />
       <label class="sampleStyleC" for="RadioC">Choose THIS Style.</label><br />
       <input id="RadioD" name="Radio" onclick="styleToSelect = 'sampleStyleD';" type="radio" />
       <label class="sampleStyleD" for="RadioD">Choose THIS Style.</label><br />
       <br />
       <div align="center">
          <asp:Button ID="OkButton" runat="server" Text="OK" />
          <asp:Button ID="CancelButton" runat="server" Text="Cancel" />
       </div>
       </asp:Panel>
       <br />
      
       <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
                 TargetControlID="LinkButton1"
                 PopupControlID="Panel1"
                 BackgroundCssClass="modalBackground"
                 DropShadow="true"
                 OkControlID="OkButton"
                 OnOkScript="onOk()"
                 CancelControlID="CancelButton" />
       </div>
        </form>
    </body>

     The styles have been added to the style sheet, and as I said the web.config has been modified.  I tested the same page in a new ajax enabled web application and it runs fine, but running it in the application converted from 2003 does nothing.  There isn't an error or anything, just a reload of the page when you click the LinkButton1.  In the sample the page doesn't reload, it displays the Panel1 above.
     

     

  • Re: Ajax on Web Application converted from 2003 to 2008

    07-22-2008, 2:25 PM
    • Loading...
    • bmains
    • Joined on 10-22-2004, 12:20 PM
    • Posts 5,070

    Hey,

    It may not be an issue related to that; try putting the following in LinkButton1:

    OnClientClick="return false;"

    I think it may be more of an issue with the linkbutton and its nature to post back than anything else...  this may or may not have a negative impact on the extender...

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: Ajax on Web Application converted from 2003 to 2008

    07-22-2008, 4:25 PM

     Well, that stopped the page from reloading, but the panel still isn't showing up.  The only reason I think the code must be fine is that it works without issue in a new project where that is the only page.  The app where it isn't working wasn't 'ajax enabled' when it was created because it was created with the wizard that updates your application from 2003 to 2008.  Maybe there is something that doesn't get converted properly when the controls etcetera are updated to 2008?  I would really like to use ajax with this site, but a re-write at this point would take forever.

  • Re: Ajax on Web Application converted from 2003 to 2008

    07-23-2008, 9:15 AM
    • Loading...
    • bmains
    • Joined on 10-22-2004, 12:20 PM
    • Posts 5,070

    Hey,

    I did the same thing (converted a non-ajax app to an ajax app).  All you have to do is copy over the web config settings, add a reference to the project, map the assembly/namespace to a tagprefix in the <pages> element of the web.config file, and add a  script manager.  That's it, at least that should be it...

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: Ajax on Web Application converted from 2003 to 2008

    07-23-2008, 9:36 AM

     Well, I've got the web.config settings, these are the two tag prefixes I have in my web.config:

            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>


            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    Do they look right?  Am I missing one?  I've also got the script manager.  What is the reference you added to the project?

  • Re: Ajax on Web Application converted from 2003 to 2008

    07-23-2008, 9:53 AM
    • Loading...
    • bmains
    • Joined on 10-22-2004, 12:20 PM
    • Posts 5,070

    Hey,

    Yes, that's correct.  You also added AjaxControlToolkit as cc1, so you can do:

    <add tagPrefix="cc1" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" />

    So that you only have to reference it once in your application.  It takes a while for this to get recognized, that I have found out.

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: Ajax on Web Application converted from 2003 to 2008

    07-23-2008, 10:56 AM

     Ok, I've got all that but it still isn't working.  I think I've eliminated the possibility of there being a problem with the web.config or the code in the page itself.  I created a new project, imported the page and web.config files from the project that isn't working, and the Ajax works fine in the new project.  If you can think of anything else I could be missing, let me know.  I've run out of ideas.  I did try importing all of the files from the old project into a new project as well, but that is another nightmare I don't want to deal with.

  • Re: Ajax on Web Application converted from 2003 to 2008

    07-23-2008, 2:42 PM

     It looks like the problem lies with IIS.  When I debug if I have the setting to Use Visual Studio Devlopment Server selected, the Ajax stuff seems to run fine, but if I select the option to Use IIS Web server selected, it stops working.  Is there something with IIS I need to do?  I already have framework 3.5 installed, but I noticed that in the ASP.NET tab of IIS the ASP.NET version drop down menu only has 1.1 and 2.0 in there.  Should 3.5 be an option?

  • Re: Ajax on Web Application converted from 2003 to 2008

    07-24-2008, 9:14 AM
    • Loading...
    • bmains
    • Joined on 10-22-2004, 12:20 PM
    • Posts 5,070

    No surprisingly, you should set it to 2.0 because the the 3.5 framework still uses the System.Web 2.0 assembly, and some of the other 2.0 assemblies.  So ensure its set to 2.0... I forgot about that.  Hmm... that seems weird; there are some changes it makes to the handlers and factories it uses... are you sure you updated everything in the configuration file?

    Sorry I can't be of more help...  the page looks like its OK, and personally all I had to do was copy over the config stuff, and it worked for me.  I didn't make any extra settings.

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: Ajax on Web Application converted from 2003 to 2008

    07-24-2008, 11:16 AM

     Thanks for your help anyways.  I'm pretty sure the web.config file is fine.  I thought it was IIS because the ajax stuff seemed to be working fine using the Visual Studio Development Server, but it has suddenly stopped working in that too, and gone back to just reloading the page when I do something with an ajax control.  Now I'm at a total loss, how could it go from working to suddenly not working for absolutely no apparent reason!  Today I hate Visual Studio. 

Page 1 of 1 (12 items)
Microsoft Communities
Page view counter