Monday, September 3, 2012

passing variables in web forms routing

I found this which illuminated that passing variables in web forms routing is much easier than I was making it. Expanding upon what I wrote here, TryToGetToMe.aspx looks like:

<%@ Page Language="C#" AutoEventWireup="true"
      CodeBehind="TryToGetToMe.aspx.cs"
      Inherits="WebFormsRoutingExample.TryToGetToMe" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head runat="server">
   <title>You made it here!</title>
   </head>
   <body>
      <form id="form1" runat="server">
         <div>
            <p>You made it here!</p>
            <p>The variable is: <%=Bar %></p>
         </div>
      </form>
   </body>
</html>

 
 

TryToGetToMe.aspx.cs looks like:

using System;
namespace WebFormsRoutingExample
{
   public partial class TryToGetToMe : System.Web.UI.Page
   {
      public string Bar;
      protected void Page_Load(object sender, EventArgs e)
      {
         Bar = Page.RouteData.Values["bar"] as string;
      }
   }
}

1 comment:

  1. Fantastic post!! Web forms routing results in success of an organization, because it saves time and money.




     Forms 

    ReplyDelete