Results 1 to 7 of 7

Thread: Dynamically changing control location

  1. #1

    Thread Starter
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Dynamically changing control location

    I want to relocate a dropdownlist control based on the login status of a user.
    How do I set the Z-Index, LEFT,POSITION etc programatically?
    Is this done via .styles?

    thx....

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: Dynamically changing control location

    Yes.

    But be aware - you want to be sure to replace the default <DOCTYPE definition VS provides for the web pages. You will want to use a fully qualified doctype decleration with the one provided below. This is especially important if your site will be viewable by browsers other than Internet Explorer.

    <!doctype html public "-//w3c//dtd html 4.0 transitional//en" "http://www.w3.org/tr/rec-html40/loose.dtd">

  3. #3

    Thread Starter
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Dynamically changing control location

    I'm not sure I understand, could you provide an example?
    I'm assuming something like DropDownList.Styles(?)
    or DropDownList.Styles(?)=?
    I'm not sure if I'm to provide as an argument or as an assignment and what method to use. THX

  4. #4
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: Dynamically changing control location

    Are you trying to change it's placement ServerSide or ClientSide? Meaning or we using JavaScript or Asp.Net?
    Magiaus

    If I helped give me some points.

  5. #5

    Thread Starter
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Dynamically changing control location

    I want to do server side.

    ie:
    txtMyTextbox.text="hello"
    txtMyTextbox.visible=false
    Are pretty straight forward but...

    MyDropDownList.Style ?????
    I think is what I want to relocate (in my case a DropDownList) on the form.

  6. #6
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: Dynamically changing control location

    Look. Page_Load and the button code.

    ASPX/HTML
    Code:
    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="tb_nDg.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    	<HEAD>
    		<title>WebForm1</title>
    		<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
    		<meta name="CODE_LANGUAGE" Content="C#">
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    	</HEAD>
    	<body MS_POSITIONING="GridLayout">
    		<form id="Form1" method="post" runat="server">
    			<asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 7px; POSITION: absolute; TOP: 7px" runat="server"></asp:DropDownList>
    			<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 145px; POSITION: absolute; TOP: 23px" runat="server" Text="Button"></asp:Button>
    		</form>
    	</body>
    </HTML>
    Coidebehind
    PHP Code:
        public class WebForm1 System.Web.UI.Page
        
    {
            protected 
    System.Web.UI.WebControls.Button Button1;
            protected 
    System.Web.UI.WebControls.DropDownList DropDownList1;
        
            private 
    void Page_Load(object senderSystem.EventArgs e)
            {
                
    // Put user code to initialize the page here
                
    DropDownList1.Style["left"] = "100px";
                
    DropDownList1.Style["top"] = "100px";
            }

            
    #region Web Form Designer generated code
            
    override protected void OnInit(EventArgs e)
            {
                
    //
                // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                //
                
    InitializeComponent();
                
    base.OnInit(e);
            }
            
            
    /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            
    private void InitializeComponent()
            {    
                
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
                
    this.Load += new System.EventHandler(this.Page_Load);

            }
            
    #endregion

            
    private void Button1_Click(object senderSystem.EventArgs e)
            {
                
    System.Random r = new System.Random(500);
                
    DropDownList1.Style["left"] = r.Next(500).ToString() + "px";
                
    DropDownList1.Style["top"] = r.Next(500).ToString() + "px";
            }
        } 
    Last edited by Magiaus; Jan 28th, 2005 at 03:26 PM.
    Magiaus

    If I helped give me some points.

  7. #7

    Thread Starter
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Dynamically changing control location [RESOLVED]

    Perfect!-Thanks just what I was looking for.

    Works great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width