占位符问题 [英] Placeholder problem

查看:76
本文介绍了占位符问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的设计包含两个占位符:placeholder1和placeholder2以及两个按钮:display1和display2.

占位符1包含图像,占位符2包含日历.

当我单击display1按钮时,将打开图像.当我单击display2按钮时,将打开日历,但同时关闭Placeholder1,反之亦然.

我希望占位符1在打开占位符2时保持打开,而占位符2在占位符1打开时保持打开.

他们不应该彼此关闭.

请帮帮我.
请提供完整代码(不在VB.net中).
请紧急.

My design contain two placeholders: placeholder1 and placeholder2 and two buttons: display1 and display2.

Placeholder1 contains Image, placeholder2 contains calender.

When I click the display1 button, the image is opened. When I click the display2 button, the calendar is opened but at same time, Placeholder1 is closed and vice versa.

I want placeholder1 to stay open when placeholder2 is opening and placeholder2 to stay open when placeholder1 is opening.

They should not close each other.

Please help me.
Please give full code (not in VB.net).
Please urgent.

推荐答案

不要将选择作为页面生成标准,而是将用户选择存储在会话中.例如:

Don''t pass the selection as page-generation criteria, rather store the user selection in the session. For example:

Session("image-choice") = "filename.jpg"



加载页面时,请检查会话中的两个选择并加载已选择的内容.

干杯.



When you''re loading the page, check the session for both selections and load the content that has been selected.

Cheers.


检查此代码.我昨天在dotnetspider中回答了这类问题.

Check this code. i answer this type of question yesterday in dotnetspider.

<![CDATA[<%@ Page Language="C#" AutoEventWireup="true" CodeFile="placeholderissue.aspx.cs" Inherits="placeholderissue" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Display1"
            onclick="Button1_Click" />
        <asp:Button ID="Button2"
            runat="server" Text="Display2" onclick="Button2_Click" />
        <br />
        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> <br />
        <asp:PlaceHolder ID="PlaceHolder2" runat="server"></asp:PlaceHolder>
    </div>
    </form>
</body>
</html>

















using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class placeholderissue : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            if (Display1)
            {
                if (PlaceHolder1.FindControl("Calendar1") == null)
                {
                    Calendar calender1 = new Calendar();
                    calender1.ID = "Calendar1";
                    PlaceHolder1.Controls.Add(calender1);
                    PlaceHolder1.Visible = true;
                }
            }
            if (Display2)
            {
                if (PlaceHolder2.FindControl("FileUpload1") == null)
                {
                    FileUpload fup = new FileUpload();
                    fup.ID = "FileUpload1";
                    PlaceHolder2.Controls.Add(fup);
                    PlaceHolder2.Visible = true;
                }
            }
        }
        else
        {
            PlaceHolder1.Visible = false;
            PlaceHolder2.Visible = false;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (PlaceHolder1.FindControl("Calendar1") == null)
        {
            Calendar calender1 = new Calendar();
            calender1.ID = "Calendar1";
            PlaceHolder1.Controls.Add(calender1);
            PlaceHolder1.Visible = true;
            Display1 = true;
        }
       
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (PlaceHolder2.FindControl("FileUpload1") == null)
        {
            FileUpload fup = new FileUpload();
            fup.ID = "FileUpload1";
            PlaceHolder2.Controls.Add(fup);
            PlaceHolder2.Visible = true;
            Display2 = true;
        }
    }
    public bool Display1 {
        get
        {
            object o = ViewState["_Display1"];
            if (o == null)
                return false;
            else
                return (bool)ViewState["_Display1"];
        }
        set
        {
            ViewState["_Display1"] = value;
        }
    }
    public bool Display2
    {
        get
        {
            object o = ViewState["_Display2"];
            if (o == null)
                return false;
            else
                return (bool)ViewState["_Display2"];
        }
        set
        {
            ViewState["_Display2"] = value;
        }
    }
}

%>]]>

%>]]>


尝试一下:-


步骤1:-

我使用两个PlaceHolder(PlaceHolder1,PlaceHolder2)和两个按钮(Display1,Display2).在PlaceHolder1中,有一个Image(Image1),在PlaceHolder2中,有一个Calendar.设置Image的Visible属性(Visible ="false")和日历控件


< asp:PlaceHolder ID ="PlaceHolder1" runat ="server">< asp:图像ID ="Image1" Visible ="false" Height ="100px" runat ="server" ImageUrl ="Blue hills.jpg" /></asp:PlaceHolder>
< br/>
< br/>
< asp:PlaceHolder ID ="PlaceHolder2" runat ="server">
< asp:日历ID ="Calendar1" Visible ="false" runat ="server"></asp:Calendar>
</asp:PlaceHolder>
< asp:按钮ID ="Display1" runat =服务器" Text ="Display1" OnClick ="Display1_Click"/>
< asp:按钮ID ="Display2"
runat ="server" Text ="Display2" OnClick ="Display2_Click"/>



步骤2:-

单击两个显示按钮,将下面的代码写入可见的两个控件(图像和日历).


受保护的void Display1_Click(对象发送者,EventArgs e)
{
Image1.Visible = true;
}
受保护的void Display2_Click(对象发送者,EventArgs e)
{
Calendar1.Visible = true;
}
Try this:-


Step 1:-

I use two PlaceHolder(PlaceHolder1,PlaceHolder2) and Two Buttons(Display1,Display2) .In PlaceHolder1,There is an Image(Image1) and in PlaceHolder2,there is a Calendar.Set the Visible property(Visible="false") of Image and Calendar Control


<asp:PlaceHolder ID="PlaceHolder1" runat="server"><asp:Image ID="Image1" Visible="false" Height="100px" runat="server" ImageUrl="Blue hills.jpg" /></asp:PlaceHolder>
<br />
<br />
<asp:PlaceHolder ID="PlaceHolder2" runat="server">
<asp:Calendar ID="Calendar1" Visible="false" runat="server"></asp:Calendar>
</asp:PlaceHolder>
<asp:Button ID="Display1" runat="server" Text="Display1" OnClick="Display1_Click" />
<asp:Button ID="Display2"
runat="server" Text="Display2" OnClick="Display2_Click" />



Step 2:-

Write the following code to visible both controls(Image and Calendar) on the Click of both Display Buttons.


protected void Display1_Click(object sender, EventArgs e)
{
Image1.Visible = true;
}
protected void Display2_Click(object sender, EventArgs e)
{
Calendar1.Visible = true;
}


这篇关于占位符问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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