methode uebergeben ?!

Neral

Mitglied
Hi
Also, ich habe nun folgende Methode, die in einem Label ausgegeben werden soll.
in der Methode habe ich den Rueckgabewert eines Strings, nur mein Problem er schreibt den String nicht in das Label?!..
Die Methode funktionniert.(quellcode wird in "htmlcode" gespeichert und zurueckgegeben)

hier die methode:

PHP:
public string auslesen()
		{
			string htmlcode = null;
			Uri url = new Uri("http://www.neral.de");
			
			//Creates an HttpWebRequest with the specified URL.     
			HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
			
			// Sends the HttpWebRequest and waits for the response.             
			HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
			
			// Gets the stream associated with the response. 
			Stream receiveStream = myHttpWebResponse.GetResponseStream(); 
			
			Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); 
			
			// Pipes the stream to a higher level stream reader with the required encoding format. 
			StreamReader readStream = new StreamReader( receiveStream, encode ); 
			
			Char[] read = new Char[256]; 
			
			// Reads 256 characters at a time.     
			int count = readStream.Read( read, 0, 256 );
			while (count > 0) 
			{ 
				// Dumps the 256 characters on a string and displays the string to the console. 
				String str = new String(read, 0, count); 
				htmlcode = htmlcode + str;
				count = readStream.Read(read, 0, 256); 
			} 
			
			// Releases the resources of the response. 
			myHttpWebResponse.Close(); 
			
			// Releases the resources of the Stream. 
			readStream.Close(); 
			
			return htmlcode;
		
		}

und wenn ich dies mir nun ausgeben lassen moechte, muss ich das doch so schreiben:

PHP:
private void Button1_Click(object sender, System.EventArgs e)
		{
			Label.Text = auslesen();

		}

beide sind in der gleichen Klasse.
hm... bin schon ganzzeit am gruebeln komme aber nicht weiter :(

gruss
 
Huhu,
nein leider gibt es keine Fehlermeldung :( :\
Das Bild wird im Browser nach ausfuehrung der Aktion(Buttonklick) nur schwarz.
Hier ich habe mal screenshot gemacht:
Oben das Bild ist die normale Eingabemaske und nachdem man auf "auslesen" klickt kommt das untere Bild.

http://www.neral.de/cfehler.jpg

Normal sollte der Text/Quellcode im Label3 erscheinen wo das rote Kreuz ist.(Bild 2)

Und ich habe Label nur irgendwie umbenannt, also normal steht da Label3.Text.

Hier nochmal der gesamte Code:

PHP:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net; 
using System.IO; 
using System.Text; 

namespace WebApplication4
{
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Label Label2;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			string texturl = TextBox1.Text;
		}

		#region Vom Web Form-Designer generierter Code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: Dieser Aufruf ist für den ASP.NET Web Form-Designer erforderlich.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Erforderliche Methode für die Designerunterstützung. 
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
		/// </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 sender, System.EventArgs e)
		{	
			
			Label1.Text = TextBox1.Text;
			Label3.Text = auslesen();
		}

		public string auslesen()
		{
			string htmlcode = null;
			Uri url = new Uri(TextBox1.Text);
			
			//Creates an HttpWebRequest with the specified URL.     
			HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
			
			// Sends the HttpWebRequest and waits for the response.             
			HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
			
			// Gets the stream associated with the response. 
			Stream receiveStream = myHttpWebResponse.GetResponseStream(); 
			
			Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); 
			
			// Pipes the stream to a higher level stream reader with the required encoding format. 
			StreamReader readStream = new StreamReader( receiveStream, encode ); 
			
			Char[] read = new Char[256]; 
			
			// Reads 256 characters at a time.     
			int count = readStream.Read( read, 0, 256 );
			while (count > 0) 
			{ 
				// Dumps the 256 characters on a string and displays the string to the console. 
				String str = new String(read, 0, count); 
				htmlcode = htmlcode + str;
				count = readStream.Read(read, 0, 256); 
			} 
			
			// Releases the resources of the response. 
			myHttpWebResponse.Close(); 
			
			// Releases the resources of the Stream. 
			readStream.Close(); 
			return htmlcode;
		
		}
	}

}

Gruss
 
Zuletzt bearbeitet:
Wenn ich mal das Ganze ueber Opera laufen lassen kommt das erstaunliche Ergebnis:

http://www.neral.de/cfehler2.jpg

der gibt nicht den Quelltext raus sonder die Seite :\ :eek: :)

gruss


-----EDIT----

Also ich habe mal das Label in eine TextBoX umgewandelt und in der TextBox wir der Quellcode ohne Probleme ausgegeben !

thx

gruss
 
Zuletzt bearbeitet:
Zurück