结合Javascript和ASP.Net [英] Combine Javascript and ASP.Net

查看:79
本文介绍了结合Javascript和ASP.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我准备好在这种情况下拔头发。

这是我的应用程序的样子。


我有一个母版页,内容页面带有一个标签容器和一个用户控件在容器的标签面板内。


在用户Cotrol我有带有文本框的表。我的任务是计算Label中两个文本框和diplay的平均值。我需要在客户端上执行此操作,以便没有回发,所以我尝试使用javascript。


声明一个Javascript函数,并尝试将其称为文本框的OnBlur。如何将txt1和txt2的值传递给函数?

Hello Everyone,

I am ready to pull my hair out with this situation.
Here is what my application Looks like.

I have a Master Page,Content Page with a Tab Container and A user Control inside the Tab Panel of the Container.

In the user Cotrol I have a Table with Textboxes. My assignment is to Calculate the average of two textboxes and diplay in a Label. I need to do that on the client so that there is no postback so I try to use javascript.

A declared a Javascript Function and try to call it OnBlur of the textbox. How do I pass the values of txt1 and txt2 to the function?

推荐答案

将函数定义为
Define the function as
展开 | 选择 | Wrap | 行号


使用func在java脚本中进行计算,然后在你在选项卡面板中使用的文本框事件中使用它
make a func to do calculation in java script then use it in events of textbox u use in your tab panel


查看这篇文章如何在ASP.NET中使用JavaScript


请注意,您必须使用ClientID TextBox用于在您使用MasterPage时检索JavaScript代码中的TextBox元素。 ClientID属性用于访问元素在呈现为HTML时所给出的ID ...


假设您有一个ID =TextBox1的TextBox ;。呈现TextBox1时,会给它一个唯一的id。由于您可以使用带有ID =TextBox1的TextBox的多个控件或页面,因此ASP.NET会将其置于自身以确保这些TextBox在呈现为HTML时被赋予唯一ID。这意味着在MasterPage中用户控件中给TextBox1的ID可能会在其中显示HTML:

Check out this article on How to use JavaScript in ASP.NET.

Please note that you have to use the ClientID of the TextBoxes in order to retrieve the TextBox elements in your JavaScript Code since you are using a MasterPage. The ClientID property is there to give you access to the ID that the element is given when it is rendered as HTML...

Say you have a TextBox with the ID="TextBox1". When TextBox1 is rendered it is given a unique id. Since you can have multiple controls or pages with a TextBox with the ID="TextBox1", ASP.NET takes it onto itself to ensure that these TextBoxes are given unique IDs when they are rendered as HTML. This means that the ID given to TextBox1 in your user control in your MasterPage might look this in it HTML:

展开 | < span class =codeLinkonclick =selectAll(this);>选择 | Wrap | 行号


这篇关于结合Javascript和ASP.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆