ASP.NET - Changing Linkbutton css styles during Runtime

Asked By Sreenath G V on 13-Apr-11 07:35 AM

Hi,

I want to change css style from the same Css file during runtime. I am doing this as follows…

aObjLnkBtn.CssClass.Remove(0, aObjLnkBtn.CssClass.Count());

 

aObjLnkBtn.CssClass = "selected";

 

But, it is not been applied. How can I achieve this.

Thanks

Sreenath

Jatin Trikha replied to Sreenath G V on 13-Apr-11 07:41 AM

aObjLnkBtn.CssClass.Remove(0, aObjLnkBtn.CssClass.Count());

//Above code line is not required

 

aObjLnkBtn.CssClass = "selected";

//Will do the need full

Sreenath G V replied to Jatin Trikha on 13-Apr-11 07:44 AM
Hi,

Yeah I tried even this, but not working...

I even tried this...

aObjLnkBtn.Attributes["class"] = "selected";

but was of no use... my link button is defined as follows...

<asp:LinkButton ID="lnkbtnApplications" runat="server" OnClick="lnkbtnApplications_Click">Application Details</asp:LinkButton></li>

Jitendra Faye replied to Sreenath G V on 13-Apr-11 07:51 AM
Once if you have set any style or css to TextBox in design time then if you will change in runtime then also it will not reflect to that control, because when postback occurs then again previous setting will be implemented to TextBox,

So don't give any css in design time, change it in runtime, then it will work.

<style type ="text/css">

.cls

{

background-color :Black

}


</style>

protected void Button1_Click(object sender, EventArgs e)

{

  TextBox1.CssClass = "cls";

}

use this code and let me know.

Sreenath G V replied to Jitendra Faye on 13-Apr-11 07:56 AM
Hi,

No I didnt gace style during design time..here u can see...

<asp:LinkButton ID="lnkbtnApplications" runat="server" OnClick="lnkbtnApplications_Click">Application Details</asp:LinkButton></li>


I am doing it during runtime only...but when I apply during design time it is working as follows...

<asp:LinkButton ID="lnkbtnApplications" CssClass="selected" runat="server" OnClick="lnkbtnApplications_Click">Application Details</asp:LinkButton></li>

Jitendra Faye replied to Sreenath G V on 13-Apr-11 08:10 AM
ok then send me your code, with .aspx with css and .cs code
Jatin Trikha replied to Jatin Trikha on 13-Apr-11 08:14 AM

aObjLnkBtn.CssClass = "selected";



use to do the trick for me probably u need to check you code there is some other error some where else which is causing this issue.