just use @ inplace of <% and %> if you are using Razor
Ashutosh Pathak
Blog: http://catchcode.blogspot.com Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
Ashutosh Pathak
Blog: http://catchcode.blogspot.com Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
You can't use UpdatePanels, ScriptManagers or ContentTemplates in .cshtml pages. So you cannot translate this using Razor syntax. It looks like a simple AJAX call that shows a message while waiting for a response. You should do that using jQuery in Web Pages.
Create a page called GetTime.cshtml and put just this in it:
@{ Layout = null; }
@DateTime.Now
Then create a page called Loading.cshtml that references jQuery and put this in it:
dow7
Member
732 Points
449 Posts
convert this aspx code to cshtml
Mar 20, 2012 11:44 AM|LINK
Hello,
can someone convert this aspx code to cshtml?
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Button_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(3000); } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>UpdateProgress Example</title> <style type="text/css"> #UpdatePanel1, #UpdatePanel2 { width:200px; height:200px; position: relative; float: left; margin-left: 10px; margin-top: 10px; border-right: gray 1px solid; border-top: gray 1px solid; border-left: gray 1px solid; border-bottom: gray 1px solid; } #UpdateProgress1, #UpdateProgress2 { width: 200px; background-color: #FFC080; position: absolute; bottom: 0px; left: 0px; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> <%=DateTime.Now.ToString() %> <br /> <asp:Button ID="Button1" runat="server" Text="Refresh Panel" OnClick="Button_Click" /> <asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="UpdatePanel1" runat="server"> <ProgressTemplate> UpdatePanel1 updating... </ProgressTemplate> </asp:UpdateProgress> </ContentTemplate> </asp:UpdatePanel> <asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server"> <ContentTemplate> <%=DateTime.Now.ToString() %> <br /> <asp:Button ID="Button2" runat="server" Text="Refresh Panel" OnClick="Button_Click"/> <asp:UpdateProgress ID="UpdateProgress2" AssociatedUpdatePanelID="UpdatePanel2" runat="server"> <ProgressTemplate> UpdatePanel2 updating... </ProgressTemplate> </asp:UpdateProgress> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html>Ashutosh Pat...
Contributor
5737 Points
1105 Posts
Re: convert this aspx code to cshtml
Mar 20, 2012 11:56 AM|LINK
just use @ inplace of <% and %> if you are using Razor
Blog: http://catchcode.blogspot.com
Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
dow7
Member
732 Points
449 Posts
Re: convert this aspx code to cshtml
Mar 20, 2012 12:09 PM|LINK
I get this error :
Compiler Error Message: CS1513: } expected
Source Error:
Line 40: } Line 41: Line 42: public override void Execute() { Line 43: Line 44:Ashutosh Pat...
Contributor
5737 Points
1105 Posts
Re: convert this aspx code to cshtml
Mar 20, 2012 12:11 PM|LINK
okay use the tool below to convert your code to cshtml(Razor)
http://visualstudiogallery.msdn.microsoft.com/d2bfd1ca-9808-417c-b963-eb1ea4896790
Blog: http://catchcode.blogspot.com
Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
Mikesdotnett...
All-Star
154927 Points
19867 Posts
Moderator
MVP
Re: convert this aspx code to cshtml
Mar 20, 2012 12:37 PM|LINK
You can't use UpdatePanels, ScriptManagers or ContentTemplates in .cshtml pages. So you cannot translate this using Razor syntax. It looks like a simple AJAX call that shows a message while waiting for a response. You should do that using jQuery in Web Pages. Create a page called GetTime.cshtml and put just this in it:
@{ Layout = null; } @DateTime.NowThen create a page called Loading.cshtml that references jQuery and put this in it:
<script> $(function(){ $.ajaxSetup ({ cache: false }); $('#button').click(function(){ $('span').text('loading...'); setTimeout(function() { $('span').load('/GetTime') }, 3000); }); }); </script> <input type="button" id="button" value="click" /> <span></span>Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
dow7
Member
732 Points
449 Posts
Re: convert this aspx code to cshtml
Mar 21, 2012 04:03 PM|LINK
Thanks,
this works, but in case i build the GetTime.cshtml page with javascript and don't want to use setTimeout function, how can i load the page?
The reason for this is that im using this script found here : http://kabo.nu/currency_widget/currency_widget/js/jquery.currency_widget.js
and i want to add a loading image to be displayed from submit to result.