简体   繁体   English

更改下拉列表索引时调用按钮的onclient click事件

[英]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.

相关问题 调用dropdownlist选择索引已手动更改事件 - call dropdownlist selected index changed event manually DropDownList 索引更改事件中具有 DropDownList 的行中的值 - Value from row with DropDownList on DropDownList Index Changed Event 当下拉列表索引更改时,文本框值消失 - Textbox Value disapear when Dropdownlist index changed 损坏按钮Onclient单击问题vb.net - Inmage button Onclient click issue vb.net 打开按钮单击弹出窗口时带按钮的下拉列表 - Dropdownlist with button when button click popup opened 在页面加载期间的数据绑定期间,未为DropDownList触发选定索引已更改事件 - Selected Index Changed event not firing for a DropDownList during databind at pageload 动态按钮未调用点击事件 - Dynamic Button not calling click event 调用按钮serveride的click事件 - Calling click event of a button serverside 如何仅在按下提交按钮时提交ASP.NET表单,而不是通过自动回发更改下拉列表的选定索引时才提交ASP.NET表单? - How to submit ASP.NET form only when the submit button is pressed and not when the selected index is changed of a dropdownlist with autopostback? C#窗体表单列表框选中索引更改事件触发表单加载和按钮单击 - C# windows forms listbox selected index changed event fires on form load and button click
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM