Created
April 5, 2014 20:30
-
-
Save stevebeauge/9997688 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ToolboxItemAttribute(false)] | |
| public class PowWebPart : WebPart | |
| { | |
| protected TextBox txtX; | |
| protected TextBox txtY; | |
| protected Button btnCalc; | |
| protected Label lblResult; | |
| protected override void CreateChildControls() | |
| { | |
| txtX = new TextBox(); | |
| Controls.Add(txtX); | |
| txtY = new TextBox(); | |
| Controls.Add(txtY); | |
| btnCalc = new Button(); | |
| btnCalc.Text = "Calculer"; | |
| btnCalc.Click += btnCalc_Click; | |
| Controls.Add(btnCalc); | |
| lblResult = new Label(); | |
| Controls.Add(lblResult); | |
| } | |
| protected override void RenderContents(HtmlTextWriter writer) | |
| { | |
| EnsureChildControls(); | |
| writer.AddAttribute(HtmlTextWriterAttribute.For, txtX.ClientID); | |
| writer.RenderBeginTag(HtmlTextWriterTag.Label); | |
| writer.Write("X"); | |
| txtX.RenderControl(writer); | |
| writer.RenderEndTag(); // Label | |
| writer.Write("<br/>"); | |
| writer.AddAttribute(HtmlTextWriterAttribute.For, txtY.ClientID); | |
| writer.RenderBeginTag(HtmlTextWriterTag.Label); | |
| writer.Write("Y"); | |
| txtY.RenderControl(writer); | |
| writer.RenderEndTag(); // Label | |
| writer.Write("<br/>"); | |
| btnCalc.RenderControl(writer); | |
| writer.Write("<br/>"); | |
| lblResult.RenderControl(writer); | |
| } | |
| private void btnCalc_Click(object sender, EventArgs e) | |
| { | |
| int x; | |
| int y; | |
| if (int.TryParse(txtX.Text, out x) && int.TryParse(txtY.Text, out y)) | |
| { | |
| lblResult.Text = Math.Pow(x, y).ToString(); | |
| } | |
| else | |
| { | |
| lblResult.Text = "Nombres invalides"; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment