English 中文(简体)
如何藏匿背后的法典中的iv
原标题:how to hide div of ascs from the code behind
  • 时间:2023-07-27 10:34:53
  •  标签:
  • c#
  • asp.net

i am trying to hide a div which written in a ascx , i am hiding it from code behind of aspx page where this ascx is registerd. here is my hidng code My div code is here :

<div class="form-group col" runat="server" id="CorpCol" visible="false">

在此,我的准则背后。

System.Web.UI.Control CorpCol = FindControlRecursive(this.Master, "CorpCol");
CorpCol.Visible = false; 
问题回答

你们必须用手法 style:

System.Web.UI.Control CorpCol = FindControlRecursive(this.Master, "CorpCol");
CorpCol.Style.Add("display", "none");

But the easiest way is to use JavaScript. You can add jQuery to project and put the following code at the bottom of your page:

<script>
$("#CorpCol").click(function(){
 var CorpCol =  document.getElementById("CorpCol").style;
 if(CorpCol.display ==  none ){
    CorpCol.display =  block ;
 }
 else{
    CorpCol.display =  none ;
 }
});
</script>

我建议你修改用户控制,并将“div”作为用户控制的公共财产。

Not only then does your code become rather simple, but you also find when you drop multiple instances of that user control on a page, then the hide/show of each "instance" of that div becomes nice clean and easy code.

因此,说用户控制选择旅馆,然后是开端,最后日期。

让我们在这种用户控制中拥有“div”——我们想隐瞒(或显示)。

因此,我们简单的用户控制标记是:

<div style="float:left">

    <h3>Select Hotel</h3>
    <asp:DropDownList ID="cboHotel" runat="server" 
        Width="200px"
        DataValueField="ID"
        DataTextField="HotelName" 
        AutoPostBack="true" >
    </asp:DropDownList>

</div>

<div style="float:left;margin-left:30px;height:100px">
    <h3>Select Start Date</h3>
    <asp:TextBox ID="txtStartDate" runat="server" TextMode="Date">
    </asp:TextBox>
</div>

<div style="float:left;margin-left:30px">
    <h3>Select Start Date</h3>
    <asp:TextBox ID="txtEndDate" runat="server" TextMode="Date">
    </asp:TextBox>
</div>

<div id="mydiv" runat="server" style="float:left;margin-left:30px">
    <h3>My div area</h3>
    <img src= <%= ResolveClientUrl(@"~/Content/Rhotel.jpg") %>  
        width="40" height="40" />
</div>

用户控制代码:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            cboHotel.DataSource =
                General.MyRst("SELECT ID, HotelName FROM tblhotelsA ORDER BY HotelName");
            cboHotel.DataBind();
            cboHotel.Items.Insert(0, "Select Hotel");
        }
    }

    public HtmlGenericControl MyDiv
    {
        get { return mydiv; }
    }

Note how we just expose the "div" as a public property. And since it is an object, then no "setter" is required, only the above "get". And note the “id" and runat="server" tag for that div.

Ok,现在我们的网页。 让用户控制下降2次,然后有2个县。 隐藏(或显示)第一个用户控制区。 第2纽顿将隐藏/how第二用户控制区。

So, this markup:

        <h3>First user control</h3>
        <uc1:USelectHotel runat="server" ID="USelectHotel" />

        <div style="clear:both"></div>
        <hr style="border:solid 2px" />

        <h3>Second user control</h3>
        <uc1:USelectHotel runat="server" ID="USelectHotel1" />

                    <div style="clear:both"></div>
        <hr style="border:solid 2px" />

        <asp:Button ID="cmdDiv1" runat="server" 
            Text="Hide show div 1" CssClass="btn btn-info" OnClick="cmdDiv1_Click"  />

        <asp:Button ID="cmdDiv2" runat="server" 
            Text="Hide show div 2" CssClass="btn btn-info"
            style="margin-left:35px" OnClick="cmdDiv2_Click"
            />

以及2个州的法典:

    protected void cmdDiv1_Click(object sender, EventArgs e)
    {
        USelectHotel.MyDiv.Visible = !USelectHotel.MyDiv.Visible;
    }

    protected void cmdDiv2_Click(object sender, EventArgs e)
    {
        USelectHotel1.MyDiv.Visible = !USelectHotel1.MyDiv.Visible;
    }

因此,我们注意到,我们如何能够在法典背后建立美容酒店。 MyDiv.Visible = 伪造。

以上结果如下:

“entergraph





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签