Blog
Jan 14

Written by: Fred Blau
1/14/2011 5:50 PM 

 In this example, when a dropdown list is selected it fires a page return via server.transfer, then executes code and sets the selected value of the dropdowlist to the previously selected value.

 

 protected void Page_PreInit(object sender, EventArgs e)
      {
           string somevar;
           somevar= (string)Session["SomeVariable"];
           if (somevar!= null)
           {
               // Execute some code
               ContentPlaceHolder cph = this.Page.Master.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
             
               DropDownList1 = (DropDownList)cph.FindControl("DropDownList1");
                if (DropDownList1 != null)
                {
                    DropDownList1.SelectedValue = somevar;
                }
           }
           else
           {
             //  Other code
          
           }
  
       }
 
 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
       {
           Session["SomeVariable"] = DropDownList1.Text;
           Server.Transfer(Request.FilePath);
  
       }
 

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 

Blog

  

Blog

You must be logged in and have permission to create or edit a blog.
  

Blog

  

Blog