• Passing Parameters To Modal Dialog From Code Behind


    We often use modal dialog to display list item or other infomation in sharepoint.we can use the following code to create a modal dialog:

    View Code
     1 <script type="text/javascript">
    2 function ShowInfo() {
    3 var options = SP.UI.$create_DialogOptions();
    4
    5 options.title = "ModalDialogTitle";
    6 options.width = 800;
    7 options.height = 400;
    8 options.url = "/_layouts/***.aspx";
    9
    10 SP.UI.ModalDialog.showModalDialog(options);
    11 }
    12 </script>

    Most of the time,we need to pass one or more parameters to it,so we change the code like this:

    View Code
     1 <script type="text/javascript">
    2 function ShowEmpInfo(para, title) {
    3 var options = SP.UI.$create_DialogOptions();
    4
    5 options.title = title;
    6 options.width = 800;
    7 options.height = 400;
    8 options.url = "/_layouts/***.aspx?para=" + para;
    9
    10 SP.UI.ModalDialog.showModalDialog(options);
    11 }
    12 </script>

    But how to pass these parameters,we can do it like this.

    Suppose that we have a button,and we want to click it to show the special infomation,pass its ToolTip property to the parameter "para" and Text property to "title",we can add a "OnClick" event to this button,and write the following code to the code behind:

    View Code
     1 protected void btn_OnClick(object sender, EventArgs e)
    2 {
    3 btn_Info_onclick(((Button)sender).ToolTip, ((Button)sender).Text, (Button)sender);
    4 }
    5
    6 protected void btn_Info_onclick(string para, string title, Button btn)
    7 {
    8 // create ECMAScript to call the dialog function and pass the parameters
    9 var script = string.Format(@"ShowEmpInfo('{0}','{1}'); ", para, title);
    10 // run the script
    11 ScriptManager.RegisterStartupScript(btn.Page, this.GetType(), "onekey", script, true);
    12 }
  • 相关阅读:
    11g SPA (sql Performance Analyze) 进行升级测试
    SPA游标采集之去除重复
    C++ 实现分数的四则运算
    计算两个数的最大公约数和最小公倍数(欧几里得算法)
    计算a月的第b个星期c
    完数问题
    求整数的最大质因子
    C++ 读取文本文件内容到结构体数组中并排序
    月饼问题PAT B1020(贪心算法)
    路径打印(set以及字符串的相关操作)
  • 原文地址:https://www.cnblogs.com/leolis/p/2366973.html
Copyright © 2020-2023  润新知