如何调用脚本里面的属性在服务器的Runat [英] How to call properties inside of a script runat at server

查看:127
本文介绍了如何调用脚本里面的属性在服务器的Runat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我需要在.aspx调用一个函数,其在如下一个标签,我遇到的问题是,我需要评估中的.cs CLAS的属性。我怎么能做到这一点?

 <脚本类型=文/ JavaScript的>
    重定向功能(){
        location.href =homePage.aspx;
    }
 < / SCRIPT>
     <脚本=服务器>
        保护无效的button1_Click(对象发件人,EventArgs的发送)
        {
            如果(东西是真的在的.cs设置propties)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(),
               ConfirmBox,如果(确认('选择的数字是不是在目录中,您希望继续吗?')==真){重定向();};,真);
            }
        }
    < / SCRIPT>


解决方案

您可以做到这一点使用命名空间:首先把你的类命名空间

 命名空间testNamespace
{
  公共类测试
    {
       公共静态布尔测试仪(INT X,int y)对
        {
            如果(X == Y)
            {
                返回true;
            }
            否则返回false;
        }
    }
}

要导入您的命名空间的使用

 <%@导入命名空间=testNamespace%GT;<脚本=服务器>
        保护无效的button1_Click(对象发件人,EventArgs的发送)
        {
            如果(test.tester(2,2))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(),
               ConfirmBox,如果(确认('选择的数字是不是在目录中,您希望继续吗?')==真){重定向();};,真);
            }
        }
    < / SCRIPT>

使用这个脚本,您可以值传递给你的类文件,验证并返回你的答案。

I have a function that i need to call in the .aspx, and its in a tag as follows, the problem i am having is that i need to evaluate a property in the .cs clas. How would I be able to accomplish this?.

<script type="text/javascript">
    function Redirect() {
        location.href = "homePage.aspx";
    } 
 </script> 
     <script runat="server"> 
        protected void Button1_Click(Object sender, EventArgs e)
        {
            if (something is true from the propties set in .cs)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(),
               "ConfirmBox", "if(confirm('The numbers selected are not in the directory, you wish to continue?') == true){Redirect();};", true);
            } 
        }
    </script>

解决方案

You can do this using Namespace: First put your class in a Namespace

namespace testNamespace
{
  public class test
    {
       public static bool tester(int x, int y)
        {
            if (x == y)
            {
                return true;
            }
            else return false;
        }
    }
}

To import your Namespace use

    <%@ Import Namespace="testNamespace" %>

<script runat="server"> 
        protected void Button1_Click(Object sender, EventArgs e)
        {
            if (test.tester(2, 2))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(),
               "ConfirmBox", "if(confirm('The numbers selected are not in the directory, you wish to continue?') == true){Redirect();};", true);
            } 
        }
    </script>

With this script you can pass values to your class file, validate it and return your answer.

这篇关于如何调用脚本里面的属性在服务器的Runat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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