Javascrip代码在Ajax TabContainer中不起作用 [英] Javascrip Code Is Not Working inside Ajax TabContainer

查看:73
本文介绍了Javascrip代码在Ajax TabContainer中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有3个TextBox(TextBox1,TextBox2,TextBox3)
如果我在TextBox1和TextBox2中给出丝毫,则总和结果将显示在TextBox3中.我正在用javascript代码执行此操作.代码运行良好

但是,如果我将它们添加到Teb容器中,则它将不起作用.

我不明白是什么问题?
谁能帮我.
[我正在使用Asp.Net]

在此先感谢
乱弹

我的代码是这样的

< script type ="text/javascript">
函数ChangeAmountBooking(){

var SigningMoney = parseFloat(document.getElementById(``TextBox1'').value);
如果(document.getElementById(``TextBox1'').value ==``''){
SigningMoney = 0;
}
var HouseRentPerpose = parseFloat(document.getElementById(``TextBox2'').value)
如果(document.getElementById(``TextBox2'').value ==``''){
HouseRentPerpose = 0;
}



document.getElementById(''TextBox3'').value = SigningMoney + HouseRentPerpose;

}
</script>

< asp:ScriptManager ID ="ScriptManager1" runat ="server">
</asp:ScriptManager>

< br/>
< br/>
< cc1:TabContainer ID ="TabContainer1" runat =服务器" ActiveTabIndex ="0"
宽度="850px">
< cc1:TabPanel runat ="server" HeaderText ="TabPanel1" ID ="TabPanel1">
< ContentTemplate>


< table>
< tr>
< td>
TextBox1</td>
< td>
< asp:TextBox ID ="TextBox1" runat ="server"></asp:TextBox>
</td>
</tr>
< tr>
< td>
TextBox2</td>
< td>
< asp:TextBox ID ="TextBox2" runat ="server"></asp:TextBox>
</td>
</tr>
< tr>
< td>
TextBox3</td>
< td>
< asp:TextBox ID ="TextBox3" runat ="server"></asp:TextBox>
</td>
</tr>
< tr>
< td>
& nbsp;</td>
< td>
& nbsp;</td>
</tr>
</table>



</ContentTemplate>
</cc1:TabPanel>
< cc1:TabPanel ID ="TabPanel2" runat ="server" HeaderText ="TabPanel2">
< ContentTemplate>

</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>



CS页面代码

受保护的void Page_Load(对象发送者,EventArgs e)
{
如果(!IsPostBack)
{
TextBox1.Attributes.Add("onblur","javascript:return ChangeAmountBooking()");
TextBox2.Attributes.Add("onblur","javascript:return ChangeAmountBooking()");

}
}

Hi,
I have 3 TextBox (TextBox1, TextBox2, TextBox3)
If I give the velue in TextBox1 and TextBox2 then the sum result is displayed in TextBox3. I am doing this in javascript code. Codes are working nicely

But if I add them inside a Teb Container then it does not works.

I cant understand what is the problem?
Can any one to help me.
[I am using Asp.Net]

Thanks in advance
Rashed

My Code is like this

<script type="text/javascript">
function ChangeAmountBooking() {

var SigningMoney = parseFloat(document.getElementById(''TextBox1'').value);
if (document.getElementById(''TextBox1'').value == '''') {
SigningMoney=0;
}
var HouseRentPerpose = parseFloat(document.getElementById(''TextBox2'').value)
if (document.getElementById(''TextBox2'').value == '''') {
HouseRentPerpose = 0;
}



document.getElementById(''TextBox3'').value = SigningMoney+HouseRentPerpose;

}
</script>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<br />
<br />
<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0"
Width="850px">
<cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
<ContentTemplate>


<table>
<tr>
<td>
TextBox1</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
TextBox2</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
TextBox3</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
</table>



</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2">
<ContentTemplate>

</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>



CS Page Code

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBox1.Attributes.Add("onblur", "javascript:return ChangeAmountBooking()");
TextBox2.Attributes.Add("onblur", "javascript:return ChangeAmountBooking()");

}
}

推荐答案

我认为Ur问题与文本框的ID有关.
当您在标签中使用文本框时,ID是动态生成的

有2种方法可以克服这个问题.

1.
在浏览器中运行ur项目并查看源文件,查看为其分配了什么ID,并在javascript中将其替换为ur
例如:
document.getElementById(''TextBox1'').value
应该随
改变 document.getElementById(''TabContainer1_TabPanel1_TextBox1'').value

2.您可以使用
]]>

]]>

根据您的项目

希望对您有帮助.
I think Ur problem is with ID of text box.
when u use textbox in tab the id is generated dynamically

there r 2 way to overcome this.

1.
run ur project in browser and view source file and see what id is assign to it and replace it with ur id in javascript
for ex:
document.getElementById(''TextBox1'').value
should change with
document.getElementById(''TabContainer1_TabPanel1_TextBox1'').value

2. u can use
]]>
or
]]>

according to ur project

I hope This will help u.


这篇关于Javascrip代码在Ajax TabContainer中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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