如何通过javascript设置文本框值来获取代码中的值 [英] How to get the value in code behind when setting the textbox value through javascript

查看:64
本文介绍了如何通过javascript设置文本框值来获取代码中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我通过javascript代码设置文本框值但是当我尝试从文本框中获取该值到数据库时它没有得到任何东西..当我调试代码时检查命令参数值为空。请告诉我该怎么办...





 使用(SqlCommand cmd =  new  SqlCommand(  insertTrusteeInfoSP,con))
{
cmd.CommandType = CommandType.StoredProcedure;
// cmd.Parameters.AddWithValue(@ TrusteeInformationId,Convert.ToInt32(txtEmployeeId.Text)) ;
cmd.Parameters.AddWithValue( @ EmployeeReferenceId,txtlinemanager。文本);
cmd.Parameters.AddWithValue( @ TrusteeName,txtTrusteeName.Text。);
// cmd.Parameters.AddWithValue(@ TrustInformationId,Session [TrustInformationId]。ToString( ));
// cmd.Parameters.AddWithValue(@ TrustInformationId,Session [ TrustInformation]。ToString());
if (chkIsDefaultSign.Checked)
{
cmd.Parameters .AddWithValue( @ IsDefaultSignatory true );
}
else
{
cmd.Parameters.AddWithValue( @ IsDefaultSignatory false );
}
if (CheckIsActive.Checked)
{
cmd.Parameters.AddWithValue( @ IsActive true );
}
else
{
cmd.Parameters.AddWithValue( @ IsActive false );
}
cmd.Parameters.AddWithValue( @ Description,txtdescription。文本);
con.Open();
result = cmd.ExecuteNonQuery();
con.Close();



我的javascript代码





 <   script     type   =  text / javascript  >  
函数OpenPopup(showPopupFor){
var popupGenerator = null;
var trusteeName = null;
popupGenerator = document.getElementById(<% = txtlinemanager.ClientID %> );
trusteeName = document.getElementById(<% = txtTrusteeName.ClientID %> );


if(popupGenerator == null)返回false;
var url = employeesearch.aspx;
var params = new Array(popupGenerator.Value);
var popupSetting =center:yes; scroll:no; edge = raised; status:no ; resizable:no; dialogWidth:400px; dialogHeight:415px;
var prevReturnValue = window.returnValue;
window.returnValue = undefined;
var pmx = window.showModalDialog(url,params, popupSetting);
if(pmx == undefined){
pmx = window.returnValue;
}
window.returnValue = prevReturnValue;
if(pmx == undefined || pmx == null){
popupGenerator.value =;
}
else {
// popupGenerator.value = pmx.toString();
popupGenerator.value = pmx [0] .toString();
trusteeName.value = pmx [1] .toString();
}
//popupGenerator.focus();
返回false;
}

< / script >




运行浏览器值的
显示在txtlinemanager文本框中,但是当我添加时这个值在命令参数上显示为空。

解决方案

使用隐藏字段..将文本框值设为隐藏字段,而不是在后面的代码中使用此隐藏字段值

发送调用此函数的代码

函数OpenPopup(showPopupFor){< br /> 


Hello,
I am setting the textbox value through javascript code but when i am trying to fetching that value from textbox to database it is not getting anything..when i debug the code the check command parameter value its empty.Please tell me how can i do this..


using (SqlCommand cmd = new SqlCommand("insertTrusteeInfoSP", con))
{
    cmd.CommandType = CommandType.StoredProcedure;
    //cmd.Parameters.AddWithValue("@TrusteeInformationId", Convert.ToInt32(txtEmployeeId.Text));
    cmd.Parameters.AddWithValue("@EmployeeReferenceId", txtlinemanager.Text);
    cmd.Parameters.AddWithValue("@TrusteeName", txtTrusteeName.Text.);
    //cmd.Parameters.AddWithValue("@TrustInformationId", Session["TrustInformationId"].ToString());
    // cmd.Parameters.AddWithValue("@TrustInformationId", Session["TrustInformation"].ToString());
    if (chkIsDefaultSign.Checked)
    {
        cmd.Parameters.AddWithValue("@IsDefaultSignatory", true);
    }
    else
    {
        cmd.Parameters.AddWithValue("@IsDefaultSignatory", false);
    }
    if (CheckIsActive.Checked)
    {
        cmd.Parameters.AddWithValue("@IsActive", true);
    }
    else
    {
        cmd.Parameters.AddWithValue("@IsActive", false);
    }
    cmd.Parameters.AddWithValue("@Description", txtdescription.Text);
    con.Open();
    result = cmd.ExecuteNonQuery();
    con.Close();


My javascript code


<script type="text/javascript">
        function OpenPopup(showPopupFor) {
            var popupGenerator = null;
            var trusteeName = null;
            popupGenerator = document.getElementById("<%= txtlinemanager.ClientID %>");
            trusteeName = document.getElementById("<%= txtTrusteeName.ClientID %>");


            if (popupGenerator == null) return false;
            var url = employeesearch.aspx";
            var params = new Array(popupGenerator.Value);
            var popupSetting = "center:yes;scroll:no;edge=raised;status:no;resizable:no;dialogWidth:400px;dialogHeight:415px";
            var prevReturnValue = window.returnValue;
            window.returnValue = undefined;
            var pmx = window.showModalDialog(url, params, popupSetting);
            if (pmx == undefined) {
                pmx = window.returnValue;
            }
            window.returnValue = prevReturnValue;
            if (pmx == undefined || pmx == null) {
                popupGenerator.value = "";
            }
            else {
                // popupGenerator.value = pmx.toString();
                popupGenerator.value = pmx[0].toString();
                trusteeName.value = pmx[1].toString();
            }
            //popupGenerator.focus();
            return false;
        }

    </script>



on running on browser value is being shown in txtlinemanager textbox but when i am adding this value on command parameters it shows empty.

解决方案

use Hideen field ..asign textbox value to hidden field, than use this hidden field value in code behind


send the code where u r calling this function

function OpenPopup(showPopupFor) {<br />


这篇关于如何通过javascript设置文本框值来获取代码中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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