Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Access parent control on button click

Posted on 2010-01-11
3
Medium Priority
?
415 Views
Last Modified: 2012-05-08
On button click, I want to access the parent (a div) of the button control. How can I do that?

On button click, in addition to performing some db operations, I have to change the div style too.
<div id="Main" runat="server">
   <asp:button id="btnSave" runat="server" onclick="btnSave_Clicked" text="Save" />
</div>

Open in new window

0
Comment
Question by:dj_user2
3 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 668 total points
ID: 26290629
0
 
LVL 3

Assisted Solution

by:infochandru
infochandru earned 668 total points
ID: 26290663
Hope this helps you

    protected void btnSave_Click(object sender, EventArgs e)
    {
        HtmlGenericControl div = (HtmlGenericControl)btnSave.Parent;
        div.Style.Add("border", "5px");
        div.Style.Add("border-color", "Red");

    }
0
 
LVL 4

Assisted Solution

by:maheshsnkr
maheshsnkr earned 664 total points
ID: 26290680
hi dj_user2,

try the below code snippet

 protected void btnSave_Clicked(object sender, EventArgs e)
    {  
        HtmlContainerControl ParentDiv = (HtmlContainerControl)btnSave.Parent;
        ParentDiv.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#ffff99;");
        // Just put a width to see whether the applied background-color is affected or not.
        // You can use the above 2 lines of code.
        ParentDiv.Style.Add(HtmlTextWriterStyle.Width, "500px");
       
    }
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Integration Management Part 2
Loops Section Overview
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question