Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. protected string to public static string

protected string to public static string

Scheduled Pinned Locked Moved C#
questiondesignhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ckruger
    wrote on last edited by
    #1

    How can i use the protected string (TextBox.Text) inside the public static function? I get the following error on the return statement: MyWebForm.test.tb1' denotes a 'field' where a 'class' was expected public class test : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox tb1; private void Page_Load(object sender, System.EventArgs e) { } public static string GetDate() { **return tb1;** }

    I 1 Reply Last reply
    0
    • C ckruger

      How can i use the protected string (TextBox.Text) inside the public static function? I get the following error on the return statement: MyWebForm.test.tb1' denotes a 'field' where a 'class' was expected public class test : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox tb1; private void Page_Load(object sender, System.EventArgs e) { } public static string GetDate() { **return tb1;** }

      I Offline
      I Offline
      imsathy
      wrote on last edited by
      #2

      u cant use a non static member inside a static function.... and if u try to convert the textbox obj into a static one they've used a this pointer to tht so throwing a error... try this code.. public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox tb; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.Label l1; protected static string s; private void Page_Load(object sender, System.EventArgs e) { getvalue(); l1.Text = WebForm1.gd(); } public string getvalue() { s = tb.Text; return s; } public static string gd() { return s; } } sathy

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups