[英]Calling the onclient click event of a button when dropdownlist index is changed
I have a dropdownlist. 我有一个下拉列表。 When an item is selected in the dropdownlist, i am populating some fields in the onselectedindexchanged event. 当在下拉列表中选择一个项目时,我正在onselectedindexchanged事件中填充一些字段。 I need to use these values and show some javscript alerts and load the page again with the new values. 我需要使用这些值并显示一些javscript警报,然后使用新值再次加载页面。 But when i tried using onchange and onselectedindexchanged events of dropdownlist, it obviously first calls the javascript onchange event and i am not able to get the populated values. 但是,当我尝试使用dropdownlist的onchange和onselectedindexchanged事件时,它显然首先调用了javascript onchange事件,但我无法获取填充值。
So i tried to use the onclientclick event of an invisible button. 所以我试图使用一个不可见按钮的onclientclick事件。 And i need to call this from onselected indexchanged event of dropdownlist. 我需要从dropdownlist的onselected indexchanged事件中调用它。
Can anyone please suggest how to do this? 有人可以建议如何做吗? Or provide some better solution to my problem. 或者为我的问题提供一些更好的解决方案。
Here is my JS function 这是我的JS功能
function changeEnvironment() {
var permission = document.getElementById("hiddenPermissionFlag").value;
if (permission == "true") {
var newEnvironment = document.getElementById('<%=ddlChangeEnvironment.ClientID %>').value;
alert("Entering " + newEnvironment + " environment");
}
else if (permission == "false") {
var environment = document.getElementById("hiddenEnvironment").value;
alert("Not required permissions. You are in " + environment + " environment");
}
return true;
}
All the HiddenFields are populated in onselectedindexchanged event in code behind file 所有HiddenFields都填充在文件后面代码中的onselectedindexchanged事件中
You can use ScriptManager.RegisterStartupScript
to call javascript function from code behind. 您可以使用ScriptManager.RegisterStartupScript
从后面的代码中调用javascript函数。
Write below line in code behind on onselectedindexchanged event of dropdown list. 在下拉列表的onselectedindexchanged事件后面的代码中的以下行中编写。 This should display alert message as written in below code. 这将显示警告消息,如以下代码所示。 You can execute your js function as required. 您可以根据需要执行js函数。
ScriptManager.RegisterStartupScript(this, typeof(string), "KEY", "javascript:alert('Alert Called');", true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.