社区
C#
帖子详情
this.MyTextBox.Text和MyTextBox.Text有什么区别?
benefactor
2007-01-15 09:54:37
请问.cs文件中使用前台web控件时,this.MyTextBox.Text和MyTextBox.Text有什么区别?this的具体含义是什么?
...全文
195
7
打赏
收藏
this.MyTextBox.Text和MyTextBox.Text有什么区别?
请问.cs文件中使用前台web控件时,this.MyTextBox.Text和MyTextBox.Text有什么区别?this的具体含义是什么?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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访问实例成员
添加动态控件.rar
public partial class Form1 : Form { public Form1() { InitializeComponent(); } Label lab = new Label();//定义在到事件外面,这样多个按钮能公用该变量 private void button1_Click(object sender, EventArgs e) { #region //动态添加多个按钮 for (int i=0;i<4;i++) { Button btn = new Button(); btn.Name = "MyButton"+i; btn.
Text
= string.Format("按钮"+i); btn.Size = new Size(72, 48); btn.Location = new Point(200, 180+70*i); this.Controls.Add(btn); } #endregion #region//动态添加标签 lab.Name = "MyLabel"; lab.
Text
= string.Format("标签"); lab.Size = new Size(72, 48); lab.Location = new Point(100, 180); this.Controls.Add(lab); #endregion #region//动态添加文本框
Text
Box tb = new
Text
Box(); tb.Name = "
My
Text
Box
"; tb.
Text
= string.Format("文本框"); tb.Size = new Size(72, 48); tb.Location = new Point(300, 180); this.Controls.Add(tb); #endregion #region//往容器内添加标签 Label lab1 = new Label(); lab1.Name = "MyLabel1"; lab1.
Text
= string.Format("标签"); lab1.Size = new Size(72, 48); lab1.Location = new Point(710, 180); panel1.AutoScroll = true; //为panel添加滚动条 panel1.Controls.Add(lab1);//为panel添加控件 panel1.BorderStyle = BorderStyle.FixedSingle;//为panel添加边框 // panel1.BorderStyle = BorderStyle.None;//为panel取消边框 #endregion } private void button2_Click(object sender, EventArgs e) { this.Controls.Remove(lab); } } }
webservice-ajax
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
•
My
Text
Box
-
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.
My
Text
Box
.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
JavaScript高级程序设计第四版学习--第十七章
title: JavaScript高级程序设计第四版学习–第十七章 date: 2021-5-27 10:02:37 author: Xilong88 tags: JavaScript 本章内容: 理解事件流 使用事件处理程序 了解不同类型的事件 可能出现的面试题: 1.了解过事件流吗? 2.事件冒泡?事件捕获? 3.绑定事件有哪些方法? 4.事件中target,currentTarget,this的
区别
? 5.H5新增的事件了解哪些? 6.事件委托? 7.事件性能问题应该注意哪些? 8.删除事.
MessageBox.Show 参数详解
1. 准备好样式 样式链接地址:C#创建Windows窗体应用程序实例1https://blog.csdn.net/qq_45037155/article/details/124005398 2. 一个参数 MessageBox.Show(
text
Box1.
Text
+ " 登录成功!"); private void button1_Click(object sender, EventArgs e) { MessageBox.Show(tex.
System.InvalidOperationException:“线程间操作无效: 从不是创建控件“
text
Box1” 跨线程操作
text
box控件
Invoke(new EventHandler(delegate { t
text
Box1.
Text
= “要写入的文本信息”; }));
C#
110,571
社区成员
642,565
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章