Beginner ASP.NET C# script problem
-
hey guys, im new to asp and c#, and i've come accross what seems to be a really stupid problem.. the book i have only has examples in VB so im kinda on my own trying to write it in C#.. if you could help me out id appreciate it!
<%@ Page Language="C#" Debug="true" %>
void btnClick(object Sender, EventArgs e) { Button btnTemp = (Button)Sender; <-------- crashes here! switch (btnTemp.Text) { case "Left": word\_image.Align = "left"; break; case "Right": word\_image.Align = "right"; break; case "Center": word\_image.Align = "center"; break; } Left.Style\["Border-Style"\] = "notset"; Right.Style\["Border-Style"\] = "notset"; Center.Style\["Border-Style"\] = "notset"; btnTemp.Style\["Border-Style"\] = "inset"; } Sam's Teach Yourself ASP.NET in 21 Days: Day 5

This is an example of text. When the above buttons are clicked, the image will move around the text accordingly.
This example demonstrates the HtmlImage and HtmlInputButton controls.
its crashing on line 6 above saying the following:
Server Error in '/' Application. -------------------------------------------------------------------------------- Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Line 4: void btnClick(object Sender, EventArgs e) Line 5: { Line 6: Button btnTemp = (Button)Sender; Line 7: switch (btnTemp.Text) { Line 8: case "Left":
its gotta be somethin simple.. at first i thought it was cause i had the 'object' keyword capitalized.. but that didnt seem to make a difference.. thanks in advance! :-D still a newb.. cut me some slack :P -dz -
hey guys, im new to asp and c#, and i've come accross what seems to be a really stupid problem.. the book i have only has examples in VB so im kinda on my own trying to write it in C#.. if you could help me out id appreciate it!
<%@ Page Language="C#" Debug="true" %>
void btnClick(object Sender, EventArgs e) { Button btnTemp = (Button)Sender; <-------- crashes here! switch (btnTemp.Text) { case "Left": word\_image.Align = "left"; break; case "Right": word\_image.Align = "right"; break; case "Center": word\_image.Align = "center"; break; } Left.Style\["Border-Style"\] = "notset"; Right.Style\["Border-Style"\] = "notset"; Center.Style\["Border-Style"\] = "notset"; btnTemp.Style\["Border-Style"\] = "inset"; } Sam's Teach Yourself ASP.NET in 21 Days: Day 5

This is an example of text. When the above buttons are clicked, the image will move around the text accordingly.
This example demonstrates the HtmlImage and HtmlInputButton controls.
its crashing on line 6 above saying the following:
Server Error in '/' Application. -------------------------------------------------------------------------------- Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Line 4: void btnClick(object Sender, EventArgs e) Line 5: { Line 6: Button btnTemp = (Button)Sender; Line 7: switch (btnTemp.Text) { Line 8: case "Left":
its gotta be somethin simple.. at first i thought it was cause i had the 'object' keyword capitalized.. but that didnt seem to make a difference.. thanks in advance! :-D still a newb.. cut me some slack :P -dzhrm.. i changed the casting to cast to an HtmlInputButton instead of just Button.. but VB doesn't do this.. is this normal? i really wish this book hadn't tricked me into thinking it had examples in vb and c#.. first 5 chapters were in both.. now its all vb.. doh! still a newb.. cut me some slack :P -dz
-
hrm.. i changed the casting to cast to an HtmlInputButton instead of just Button.. but VB doesn't do this.. is this normal? i really wish this book hadn't tricked me into thinking it had examples in vb and c#.. first 5 chapters were in both.. now its all vb.. doh! still a newb.. cut me some slack :P -dz
Should have bought Wrox's "Beginning ASP.NET with C#" :-O Mark Sanders sanderssolutions.com
-
Should have bought Wrox's "Beginning ASP.NET with C#" :-O Mark Sanders sanderssolutions.com