this.MyTextBox.Text和MyTextBox.Text有什么区别?

benefactor 2007-01-15 09:54:37
请问.cs文件中使用前台web控件时,this.MyTextBox.Text和MyTextBox.Text有什么区别?this的具体含义是什么?
...全文
195 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
huwei001982 2007-01-15
  • 打赏
  • 举报
回复
表面上看起来一样, 其实....


其实也一样
benefactor 2007-01-15
  • 打赏
  • 举报
回复
我试了好像一样,所以才来问。。。。
python二级题库 2007-01-15
  • 打赏
  • 举报
回复
this是這的意思啊,伙計你自己去試哈不就曉得了嗎?哈哈﹗
happyxuying 2007-01-15
  • 打赏
  • 举报
回复
^o^
北京的雾霾天 2007-01-15
  • 打赏
  • 举报
回复
用this能更准确的表达对象所在的范围,就像如下的方法中的参数一样:

private string Text;
public void SetSomeValue(string Text)
{
this.Text=Text;//如果这里写成Text=Text不就有歧义了吗?加上this就没有了.
}
skinny8306 2007-01-15
  • 打赏
  • 举报
回复
没分不告诉你,哈
johnsondong 2007-01-15
  • 打赏
  • 举报
回复
用this访问实例成员
In order to AJAX enable it we will have to add the following attribute to the Web Service declaration part:
[System.Web.Script.Services.ScriptService()]
When this is done our Web Service is ready to respond to client-side JavaScript calls.
One more thing has to be done here: we need the Web Method that we will call from client-side JavaScript. Let us define it like this:
[WebMethod]
public string GetServerResponse(string callerName)
{
if(callerName== string.Empty)
throw new Exception("Web Service Exception: invalid argument");

return string.Format("Service responded to {0} at {1}", callerName, DateTime.Now.ToString());
}
Configuring ASP.Net Application
ASP.Net applications web.config file also has to be modified in order to enable Web Service calls from client-side JavaScript code.
This modification is though made for you by Microsoft Visual Studio 2005 if you are using ASP.Net AJAX template. Here is the example of what can be inserted into httpHandles section of your web.config file:

...

...



...

...

...

Making client-side JavaScript code
Let us take a look at the default.aspx file that was automatically created in our project (if it was not - then you will have to add one manually). First we have to make sure that we have one and only one instance of Script Manager object on your page:







Then we have to add Services collection to our ScriptManager object, add ServiceReference to the Services collection and specify Path to the desired service.
The result might look like this:










or like this if you prefer to do it directly in your code-behind file :
ScriptManager1.Services.Add(new ServiceReference("~/WebServices/MyWebService.asmx"));
Now we need some client-side functions, button to trigger Web Service request and a text box to provide the input for the Web Service:
• SendRequest - this function will send asyncroneus request to the Web Service
• OnComplete - this function will receive result from the Web Service
• OnError - this function will be triggered if an error occures while executing Web Service
• OnTimeOut - this function will be triggered if Web Service will not respond
MyTextBox- text box with the input for the Web Service
• RequestButton - the button that triggers SendRequest function
The result might look like this:
Collapse

Web Service call from client-side JavaScript
<script language="javascript" type="text/javascript">
function SendRequest()
{
MySampleService.GetServerResponse(form1.MyTextBox.value, OnComplete, OnError,
OnTimeOut);
}
function OnComplete(arg)
{
alert(arg);
}
function OnTimeOut(arg)
{
alert("timeOut has occured");
}
function OnError(arg)
{
alert("error has occured: " + arg._message);
}














This is basically it. You have a functioning client-side JavaScript code that calls server-side Web Service and treats returned response.
If we supply empty input value to the GetServerResponse method of MySampleService then as expected it will throw an exception. This exception will be caught by the OnError function in the client-side JavaScript:

Conclusion
The described client-to-server communication model where client-side JavaScript code invokes Web Service methods provides us with a lot of flexibility to extend the web site functionality. At the same time the traffic is minimal: we send only the input data required by the Web Method and we receive only the return value from the method being invoked.
History
You can always find the most up-to-date version of this article in the AJAX section of my web site.
About semenoff

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧