在asp.net中的类文件中有疑问 [英] Doubt in Class file in asp.net

查看:71
本文介绍了在asp.net中的类文件中有疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Developers,



我对弹出窗口有疑问.在我的应用程序中,我有两个页面(parent.aspx和child .aspx).孩子. Aspx代表弹出窗口.在我的parent.aspx页面中有一个按钮打开子项".当我单击父页面中的添加"按钮时,将打开弹出窗口(即child.aspx).

我的要求是

1.我要在两个网页之间实现class1.cs.当我单击父页面中的按钮时,它将在类文件中调用方法或函数,并且该方法调用将打开child.aspx(弹出窗口).通过使用脚本.

2.当child.aspx(弹出窗口)打开时,用户不应允许访问parent.aspx.但是父页面可以在弹出窗口后面查看.
3.关闭child.aspx(弹出窗口)后,只有用户才能访问父页面(即parent.aspx)

在此先感谢

任何人都可以帮助我..........

Hi Developers,



I have doubt in popup window. In my application, I have two page (parent.aspx and child .aspx) . Child. Aspx which represent pop up window. In my parent.aspx page have one button "open child".When I click add button in the parent page, that will open popwindow (i.e. child.aspx).

My requirement is

1. I want to implement the class1.cs in between the two webpage. when i click button in parent page, it will call method or function in class file and the method call to open child.aspx(popup window). by using script.

2. when child.aspx (popup window) opens, the user should not allow to access the parent.aspx.. But parent page could view behind the popup window..

3. after we close the child.aspx(popup window), then only user can access the parent page(i.e.parent.aspx)

Thanks In Advance

Any one help me..........

推荐答案

从父页面中调用函数callchildwindwind()如下所示

Call function callchildwindow() as shown below from parent page

<script language="javascript">
        function callchildwindow() {           
           var s="height:200;width:200";          
           window.showModalDialog("Child.aspx", "new", s);        
        }
    </script>


按照以下步骤解决您的问题...

对于(1)

打开解决方案资源管理器..右键单击项目名称..选择添加ASP.NET文件夹并选择App_Code文件夹...

现在,选择新添加的App_Code"文件夹.右键单击它..选择添加新项"..从列表中选择类",然后输入适当的名称,然后添加..假设类名称为Class1.cs

现在打开此Class1.cs并使用以下语法在其中写入所需的函数

公共静态返回类型的函数名(参数列表)
{
//函数主体
}


之后,您可以通过这种方式在所有aspx.cs文件中调用此.cs文件中声明的所有函数

Class1.functionname(argumentlist);
Follow following Steps to Solve your Problem...

For (1)

Open Solution Explorer..Right Click in Project Name..Select add ASP.NET Folder & Select App_Code folder...

Now Select Newly Added App_Code folder.Right Click on it..Select Add New Item..Select Class from list give appropriate name & then add..Suppose class name is Class1.cs

Now Open this Class1.cs & Write required functions in it using fillowing syntax

public static return-type functionname(argumentlist)
{
// function body
}


After this you can call all the function declared in this .cs file in all your aspx.cs files by this way

Class1.functionname(argumentlist);


To achieve your requirement no need to write that function in Class1.cs...Follow following Procedure

add following function is <script> block of .aspx page

<script type="text/javascript">
function OpenPopWin(varURL, varWindowName, varCaller, varKeyId, varWidth, varHeight) {
    var objTransparent = document.getElementById("Transparent");
    var height = document.body.clientHeight + 'px';
    document.documentElement.scrollTop = 0;


    if (navigator.appName == "Microsoft Internet Explorer")
        objTransparent.style.height = "100%";
    else
        objTransparent.style.height = height;

    objTransparent.style.width = "100%";

    objTransparent.style.visibility = 'visible';

    var varLeft = (screen.width / 2) - (varWidth / 2);
    var varTop = (screen.height / 2) - (varHeight / 2);


    popupWindow = window.open(varURL + 'Caller=' + varCaller + '&Id=' + varKeyId + '&ShowModal=1', varWindowName, 'width=' + (screen.width - 10) + 'px; height=' + (screen.height - 70) + 'px; top=' + 0 + '; left=' + 0 + '; location=0 ;resizable=1; scrollbars=1');


}
</script>

Now call this function from code behind...Here i assume that you have call this function on Button Click...Name of that button is Button1

 protected void Button1_Click(object sender, EventArgs e)
    {
        // Here i assume that you want to navigate from first.aspx(Parent Window) to second.aspx(Pop-up window)
        string str = Guid.NewGuid().ToString();
        str = str.Replace('-', '0');
        str = "w" + str;
        string Name="shankumar_cst";
    string url = "Second.aspx?Name=" + Name + "&";
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(@"<script language='javascript'>");
        sb.Append(@"OpenPopWin('" + url + "','" + str + "', 'first.aspx', '" + -1 + "', '1024', '620');");
        sb.Append(@"</script>");
        System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "JCall2",sb.ToString(), false);
    }


这篇关于在asp.net中的类文件中有疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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