Advertisement
tsnaik

WDDN lab 5

Aug 13th, 2015
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. /**
  2. *WDDN lab 5
  3. *@Tanmay Naik
  4. */
  5.  
  6.  
  7. 1. counter using static variable
  8.  
  9. namespace WebApplication11
  10. {
  11.     public partial class WebForm1 : System.Web.UI.Page
  12.     {
  13.         static int i=0;
  14.  
  15.         protected void Page_Load(object sender, EventArgs e)
  16.         {
  17.            
  18.         }
  19.  
  20.         protected void Button1_Click(object sender, EventArgs e)
  21.         {
  22.             Label1.Text = i.ToString();
  23.             i++;
  24.         }
  25.     }
  26. }
  27.  
  28.  
  29. 2. Using ViewState counter
  30.  
  31.  protected void Button1_Click(object sender, EventArgs e)
  32.         {
  33.             int counter;
  34.  
  35.             if (ViewState["Counter"] == null)
  36.             {
  37.  
  38.                 counter = 1;
  39.  
  40.             }
  41.  
  42.             else
  43.             {
  44.  
  45.                 counter = (int)ViewState["Counter"] + 1;
  46.  
  47.             }
  48.  
  49.             ViewState["Counter"] = counter;
  50.  
  51.             Label1.Text = counter.ToString();
  52.         }
  53.  
  54.  
  55. 3. passing textbox using querystring
  56.  
  57. protected void Button1_Click(object sender, EventArgs e)
  58.         {
  59.             string url = "WebForm2.aspx?" + "name=" + Server.UrlEncode(TextBox1.Text);
  60.            
  61.             Response.Redirect(url);
  62.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement