简体   繁体   English

从此页面访问其他页面控件

[英]Accessing Other Page Controls From This Page

Page 1 - Ticket.aspx , DropDownList1 , ModalPopUpextender with id mpe 1 - Ticket.aspxDropDownList1ModalPopUpextender ID为mpe

Page 2 - Customer.aspx , btnSave 第2页- Customer.aspxbtnSave

The index change event of dropdown will pop up mpe which has an iframe . 下拉的指数变化情况,会弹出mpe它有一个iframe This iframe loads Customer.aspx . iframe加载Customer.aspx

I am trying to access page1 controls in the button click event, but unable to. 我正在尝试在按钮单击事件中访问page1控件,但无法访问。

Customer.aspx.cs: Customer.aspx.cs:

protected void btnSave_Click()
{
  Ticket page = new Ticket();
  ModalPopUpExtender mpe = (ModalPopUpExtender)page.FindControl("mpe");
  DropDownList ddl = (DropDownList)page.FindControl("DropDownList1");

  //error here - Object reference not set to an instance

    mpe.hide();

    ddl.selectedindex=0;
}

Why is this not working. 为什么这不起作用。 Using a Session variable should work right? 使用Session变量应该正确吗?

You may use Server.Transefer instead of Response.Redirect and then you can find the control in the current page. 您可以使用Server.Transefer代替Response.Redirect,然后可以在当前页面中找到该控件。 Like: 喜欢:

TextBox tb = (TextBox)PreviousPage.FindControl("textbox1");

EDIT: 编辑:

if (Page.PreviousPage != null)
{
    DropDownList ddl1 = 
        (DropDownList)Page.PreviousPage.FindControl("DropDownList1");
    if (ddl1 != null)
    {
        Label1.Text = ddl1.SelectedItem.Text; //your logic
    }
}

What you are trying may not be doable from the server side, but it can be easily be done with a little javascript. 您尝试的操作可能无法在服务器端实现,但是只需使用一些JavaScript即可轻松完成。 Here is a link where you can get a working piece of code. 这是一个链接 ,您可以在其中获得有效的代码。

Hope this helps. 希望这可以帮助。

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

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