控件在服务器端事件中丢失javascript函数中设置的值 [英] Control looses value set in javascript function on server side event

查看:38
本文介绍了控件在服务器端事件中丢失javascript函数中设置的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在javascript函数中我检查复选框并在满足条件后设置值到标签。但是在服务器端事件中我得到checkbox1.checked = false,标签文本是该标签的默认文本,没有修改过。为什么这是发生了什么?如何处理?



我尝试过:



我在javascript中使checkbox1.checked == true

解决方案

这是我尝试使用该方案的实现: -



 <   p  >  
< asp:checkbox id = chkTest runat = server clientidmode = 静态 xmlns:asp = #unknown / >
< asp:label id = lblTest runat = 服务器 text = 标签 clientidmode = 静态 xmlns:asp = #unknown > < / asp:标签 >
< / p >
< p >
< asp:按钮 id = btnTest runat = server text = 按钮 onclick = btnTest_Click xmlns:asp = #unknown / >
< / p >







Javascript C.颂歌: -



< script type =   text / javascript> 


function (){
document .getElementById(' chkTest' ).checked = true ;


' #lblTest')。text(' Smruti') ;
});
< / script>





在ServerSide按钮上点击: -



  protected   void  btnTest_Click( object  sender,EventArgs e)
{
bool val = chkTest.Checked;
}





我认为属性值

 ClientIDMode =Static

是你需要照顾的事情。



如果这有用或请分享你的代码请告诉我们我们会分析得到的东西完成。


In javascript function I checking checkbox and setting value to label after satisfication of perticular condition.But in serverside event I am getting checkbox1.checked = false and text of label is default text of that label, not modified one.Why this is happening?How to handle that?

What I have tried:

I made checkbox1.checked== true in javascript

解决方案

Here is the implementation i tried with the scenario:-

<p>
        <asp:checkbox id="chkTest" runat="server" clientidmode="Static" xmlns:asp="#unknown" />
        <asp:label id="lblTest" runat="server" text="Label" clientidmode="Static" xmlns:asp="#unknown"></asp:label>
    </p>
    <p>
        <asp:button id="btnTest" runat="server" text="Button" onclick="btnTest_Click" xmlns:asp="#unknown" />
    </p>




Javascript Code:-

<script type="text/javascript">


(function () { document.getElementById('chkTest').checked = true;


('#lblTest').text('Smruti'); }); </script>



On ServerSide button click:-

protected void btnTest_Click(object sender, EventArgs e)
        {
            bool val = chkTest.Checked;
        }



I think the property value

ClientIDMode="Static"

is the thing which you have to take care.

Please let me know if this is helpful or please share your code and we will analyse to get the things done.


这篇关于控件在服务器端事件中丢失javascript函数中设置的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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