面板在按钮单击中可见 [英] Panel Visible in button click

查看:74
本文介绍了面板在按钮单击中可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在面板中显示日历。



我想要只有在点击按钮时才会显示日历。



我试过但它还没来。



请帮忙。



Hi,

I am displaying a calender inside a panel.

And I want to show the calender only when the button is clicked.

I have tried but it's not coming.

Please help.

static int flag = 0;
protected void Page_Load(object sender, EventArgs e)
{
    if (flag == 1)
    {
        pnlCal1.Visible = true;
    }
    if (flag == 0)
    {
        pnlCal1.Visible = false;
    }
    if (!IsPostBack)
    {
        flag = 1;
        pnlCal1.Visible = false;
    }
}
protected void imgDate1_Click(object sender, ImageClickEventArgs e)
{
    pnlCal1.Visible = true;
}

protected void calDate1_SelectionChanged(object sender, EventArgs e)
{
    txtDate1.Text = calDate1.SelectedDate.ToShortDateString();
    //pnlCal1.Visible = false;
    flag = 0;
}





请帮助



Please help

推荐答案



       此处您尚未指定您使用的日历(内置日历控件或第三方工具)。但根据你的情况,我认为你正在使用内置的日历控制。

然后你可以这样做。

Hi,
       Here you have not specified which calender you are using(either inbuilt calender control or third party tool). But according to your situation i think you are using inbuilt calender control.
Then you can do it like this.
//design side
//make by default visible false
<asp:Panel ID="pnlCal1" runat="server" Visible="false">
      <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</asp:Panel>
<asp:ImageButton ID="imgDate1" runat="server" OnClick="imgDate1_Click" />




protected void Page_Load(object sender, EventArgs e)
{
    // you don't need to do complex logic here!!!!!
}

protected void imgDate1_Click(object sender, ImageClickEventArgs e)
{
    pnlCal1.Visible = true;  // just make visible here
}



希望它可以帮到你。

谢谢。


Hope it helps you.
Thanks.


加价:



Markup:

<asp:Button ID="Button1" runat="server" Text="show panel"

       OnClick="Button1_Click" />
   <asp:Label ID="Label1" runat="server"></asp:Label>
   <asp:Panel ID="Panel1" runat="server" Visible="false">
       <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged">
       </asp:Calendar>
   </asp:Panel>









代码背后:





Code behind:

protected void Button1_Click(object sender, EventArgs e)
    {
        Panel1.Visible = true;
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        Panel1.Visible = false;
        Label1.Text = Calendar1.SelectedDate.ToLongDateString();
    }






这篇关于面板在按钮单击中可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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