简体   繁体   English

在客户端按钮单击事件中无法使用<%…%>

[英]Unable to use <% … %> in a client side button click event

I am trying to redirect to a different page based upon a value in the querystring. 我正在尝试根据查询字符串中的值重定向到其他页面。 This is an asp.net web form page. 这是一个asp.net Web表单页面。 When the cancel button is clicked the following js should execute. 单击取消按钮后,应执行以下js。 The button is an devexpress button. 该按钮是devexpress按钮。

function OnCancelClick(s, e) {
    if (confirm('If you leave this page, you have to reselect the benefits. Are you sure to leave this page?')) {
        var callingPage = document.getElementById("<%= CallingPage.ClientID %>").value;
        alert("Calling Page: " + callingPage);
        if (callingPage == "AddEmployee.aspx") {
            window.location.href = ResolveUrl('~/Member/Maintenance/AddEmployee.aspx?from=VerifyPage');
        } else if (callingPage == "AddDependentMember.aspx") {

        }
    }

CallingPage is the ID of an asp hidden field. CallingPage是asp隐藏字段的ID。 I am setting its value during the page load. 我在页面加载期间设置其值。 Even before this page is loaded I am getting The Controls collection cannot be modified because the control contains code blocks (ie <% ... %> ) error. 甚至在加载此页面之前,我就无法修改控件集合,因为控件包含代码块(即<% ... %> )错误。 Not sure whether it is due to devexpress button control or something else. 不确定是否是由于devexpress按钮控件或其他原因引起的。

Assign the CallingPage.ClientID to a server side page variable with public accessibility: 将CallingPage.ClientID分配给具有公共可访问性的服务器端页面变量:

public partial class <class / page name> : System.Web.UI.Page
{
    public string callingPage = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        this.callingPage = CallingPage.ClientID;

        ...
    }
}

then in your javascript: 然后在您的JavaScript中:

var callingPage = document.getElementById("<%= this.callingPage %>").value;

Actually this is an unique issue related to devexpress controls. 实际上,这是与devexpress控件相关的独特问题。 It looks like that we can't use <% %> within the js clientside click event of a devexpress button click event. 看来我们不能在devexpress按钮click事件的js客户端click事件中使用<%%>。 Instead I used devexpress's hidden control, then it worked fine. 相反,我使用了devexpress的隐藏控件,然后效果很好。 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM