views:

1214

answers:

2

I know this should be real simple, but I have googled this problem and I do not see the same available properties for my button. What I have googled says I should be able to change an HTML button's location with the Location property. However, this is not an option for me. How do I change the button's location dynamically in C#? Here is the relevant code in the ASPX.CS file:

protected void btnSubmit_Click(object sender, System.EventArgs e)
{
    int cnt = FindOccurence("DropDownListID");
    AppendRecords();
    pnlDisplayData.Visible = false;
    btnSubmit.Visible = false;
    resultLabel.Attributes.Add("style", "align=center"); 
    resultLabel.Visible = true;
}

I want to reposition btnSubmit. In the ASPX file this button is defined as:

<asp:button id="btnSubmit" runat="server" text="Submit" width="150px" 
style="top:auto; left:auto"
OnClick="btnSubmit_Click"></asp:button>
+1  A: 

The only thing wrong with your code I can see at the moment is that this line:

resultLabel.Attributes.Add("style", "align=center");

should read:

resultLabel.Attributes.Add("style", "align:center");

CSS properties are done like:

property:value;

NOT:

property=value;
Darko Z
Darko, I appreciate your suggestion. I didn't fully explain what I wanted. I wanted to reposition this button not only horizontally but also vertically. Thank you!
salvationishere
A: 

set style on control using Style collection, this will add properly style to existing styles on control defined inline:

resultLabel.Style.Add("align", "center");
btnSubmit.Style.Add("top", "auto");
btnSubmit.Style.Add("left", "auto");

setting exact absolute location of button:

btnSubmit.Style.Add("position", "absolute");
btnSubmit.Style.Add("top", "10");
btnSubmit.Style.Add("left", "10");
Andrija
Thanks Andrija, this was exactly what I needed!
salvationishere