Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Beginner ASP.NET C# script problem

Beginner ASP.NET C# script problem

Scheduled Pinned Locked Moved ASP.NET
helpcsharpdebugginglearningasp-net
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dazinith
    wrote on last edited by
    #1

    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 
    

    ![](dominos.jpg)
    

    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

    D 1 Reply Last reply
    0
    • D dazinith

      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 
      

      ![](dominos.jpg)
      

      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

      D Offline
      D Offline
      dazinith
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • D dazinith

        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

        M Offline
        M Offline
        Mark Sanders
        wrote on last edited by
        #3

        Should have bought Wrox's "Beginning ASP.NET with C#" :-O Mark Sanders sanderssolutions.com

        D 1 Reply Last reply
        0
        • M Mark Sanders

          Should have bought Wrox's "Beginning ASP.NET with C#" :-O Mark Sanders sanderssolutions.com

          D Offline
          D Offline
          dazinith
          wrote on last edited by
          #4

          hehe i just got back from the bookstore returning the other and saw your msg :) thats the book i exchanged for.. hope its good! still a newb.. cut me some slack :P -dz

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups