Skip to main content

Pass Values Between ASP.NET Web Pages without Session or any State Management

If the source page and target page are both ASP.NET Web pages in the same Web application, and if you transfer execution from the source page to the target page on the server by using the transfer method, the target page can access public properties in the source page.

Page One

<asp:TextBox ID="textCity" runat="server" Text="Brjesh"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

 public String CurrentCity
        {
            get
            {
                return textCity.Text;
            }
        }

        public List<String> Current
        {
            get
            {
                return _Current;
            }
        }
        private List<String> _Current = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            _Current = new List<String>();
            _Current.Add("1");
            _Current.Add("2");
            _Current.Add("3");
            _Current.Add("4");
            _Current.Add("5");


        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Server.Transfer("PageTwo.aspx");
        }


Page Two

<%@ PreviousPageType VirtualPath="~/PageOne.aspx" %> 

        public string strName { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            strName = PreviousPage.CurrentCity;
            List<String> Current = PreviousPage.Current;
        }
 

Comments

Popular posts from this blog

Tata Punch: A Compact SUV That Packs a Punch

Postback Page using Javascript in ASP.net

Postback Page using Javascript in ASP.net For Calling Function: __doPostBack('__Page', ''); Function: function __doPostBack(eventTarget, eventArgument) {         if (!theForm.onsubmit || (theForm.onsubmit() != false)) {             theForm.__EVENTTARGET.value = eventTarget;             theForm.__EVENTARGUMENT.value = eventArgument;             theForm.submit();         }     }

QueryString Encode & Decode

QueryString Encode & Decode Helper Class public class clsQueryString { static public string QueryStringEncode( string value) { return clsEncryptionDecryption .GetEncrypt(value); } static public string QueryStringDecode( string value) { return clsEncryptionDecryption .GetDecrypt(value); } public static string GetValueFromQueryString( string value, string key) { string strValue = string .Empty; if (value != null ) { string DataString = clsEncryptionDecryption .GetDecrypt(value); Hashtable objHash = clsQueryString .GetQueryString(DataString); strValue = clsCheckDBNull .ConvertToStr(objHash[key]); return strValue; } else return "" ; } publi...