CLASS PROBLEM

S

Savas Ates

<%@ WebService Language="C#" Class="Tecrube" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://www.aaaa.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class Tecrube : System.Web.Services.WebService {
public DateTime Tarih;
public Tecrube()
{
Tarih = DateTime.Now;
}

[WebMethod]
public string MerhabaDunya()
{
return Tarih.ToString();
}

}

Using System;
using System.Windows.Forms;

namespace WS_Tecrube_01
{
public partial class Form2 : Form
{
private WebSeTcrb.Tecrube S;
public Form2()
{
InitializeComponent();
S = new WebSeTcrb.Tecrube();
}

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = S.MerhabaDunya();
}
}
}

When i click the Button1 it returns the time when i clicked the button. I
suppose to see the time when the form initiliaze.
What can be the problem ?
 
M

Marc Gravell

When you click the button, clientside javascript (inserted by ASP.NET)
resubmits the page, and the form data detects that we clicked this button
and invokes the button1_Click() handler. You are seeing the "S" from the
second drawing of the page. Incidentally, this usage will not use the
[WebMethod] - so this may not be requireed. If you need to persist the "S"
between calls, you will need to use state (either view-state or
session-state), as ASP.NET is generally stateless.

Marc
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

You can call & store the value in Form2's constructor:

public partial class Form2 : Form
{
private WebSeTcrb.Tecrube S;
string s;
public Form2()
{
InitializeComponent();
S = new WebSeTcrb.Tecrube();
s = S.MerhabaDunya();
}

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = s; }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top