poliveira1978 Posted March 31, 2012 at 08:33 PM Report #446818 Posted March 31, 2012 at 08:33 PM Boa noite. Estou a fazer uma página com um wizard e já consigo preencher os steps com campos da BD. O meu problema é como atribuir code-behind a esses passos se o wizard só existe em runtime. Em seguida excertos do código: ASPX <body> <form id="form1" runat="server"> <div> <asp:PlaceHolder ID="PlaceHolder1" runat="server"/> </div> </form> </body> C# protected void Page_Load(object sender, EventArgs e) { Wizard Wizard1 = new Wizard(); Wizard1.ID = "Wizard1"; SqlConnection conn = new SqlConnection(Database.ConnectionString); //Database.Connection definida numa classe conn.Open(); SqlDataAdapter sda = new SqlDataAdapter("select * from Categorias", conn); DataSet ds = new DataSet(); sda.Fill(ds, "Categorias"); for (int i = 0; i <= ds.Tables["Categorias"].Rows.Count - 1; i++) { WizardStepBase newStep = new WizardStep(); newStep.ID = ds.Tables["Categorias"].Rows[i]["idCategoria"].ToString(); newStep.Title = ds.Tables["Categorias"].Rows[i]["Categoria"].ToString(); Label label = new Label(); Label label2 = new Label(); label.Text = i+" - Nome: "; label.AssociatedControlID = "txtName" + i; TextBox textbox = new TextBox(); textbox.ID = "txtName" + i; newStep.Controls.Add(label); newStep.Controls.Add(textbox); newStep.Controls.Add(label2); Wizard1.WizardSteps.Add(newStep); } PlaceHolder1.Controls.Add(Wizard1); } Agradeço qualquer dica.
petvetbr Posted March 31, 2012 at 09:48 PM Report #446829 Posted March 31, 2012 at 09:48 PM Você terá que adicionar handlers de eventos dos controles usando o operador+=. Exemplo button1.Click += button1.Click(.....,.....) Procure por "codebehind event handler" Fernando Lage Bastos - MCP/MCTS/MCPD
poliveira1978 Posted April 1, 2012 at 08:50 PM Author Report #446958 Posted April 1, 2012 at 08:50 PM Obrigado, resolveu o problema. A titulo de curiosidade para localizar os botões em cada passo do wizard utilizei o seguinte código: Devolve o nome do controlo dentro do Wizard private Control GetControlFromWizard(Wizard wizard, int passo, string controlName) { System.Text.StringBuilder strCtrl = new System.Text.StringBuilder(); if (passo == 1) { strCtrl.Append("StartNavigationTemplateContainerID"); } else if ((1 < passo) && (passo < 10)) // O meu Wizard tem 10 passos, tenho que melhorar isto de forma a obter a contagem programaticamente { strCtrl.Append("StepNavigationTemplateContainerID"); } else strCtrl.Append("FinishNavigationTemplateContainerID"); strCtrl.Append("$"); strCtrl.Append(controlName); return wizard.FindControl(strCtrl.ToString()); } Encontrar o botão e definir propriedades Button btnStartNext = GetControlFromWizard(Wizard1, 1, "StartNextButton") as Button; Button btnStepPrevious = GetControlFromWizard(Wizard1, 2, "StepPreviousButton") as Button; Button btnFinishPrevious = GetControlFromWizard(Wizard1, 10, "FinishPreviousButton") as Button; Button btnFinish = GetControlFromWizard(Wizard1, 10, "FinishButton") as Button; btnStartNext.Click += new EventHandler(btnStartNext_Click); btnFinish.Click += new EventHandler(Fim);
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now