I have a div which I set the styling from overflow:auto to display:none depending on which buttons are pressed. Is there a way to retrieve which current styling it has and return that value as a string or something in C#?
You can give the div element the runat="server" tag, and access it in codebehind (it is a HtmlGenericControl.
You can get/set the Style property of the div control via ".Style.Value".
<div id="Foo" runat="server"></div>
CodeBehind example:
string myStyle = Foo.Style.Value;
Foo.Style.Value = "padding: 0px;";
Related
I have a div of the form
<div id="mydiv" runat="server" style="display:none"></div>
In my code behind, I attempt to change the display to block by
mydiv.Style["display"] = "block";
When I view the source code after the piece of code above is run, the page source reflects the change (i.e. the div's display is set to block) but the visible page does not. How can I get my page to show the div?
Where is your code mydiv.Style["display"] = "block";? I just test it in Page_Load,and in the view page,it displayed,and the code in page source is this
<div id="mydiv" style="display:block;">12345</div>
I set innerhtml to have a good view
I am trying to enable/disable a "a" tag that's in my html code through my C# back code. I know if it was a button then I would just use, xxx.Visible="false/true" but i guess "a" tag does not have any features for backend code. Here is what I have,
c#:
if (Session["SessionUsersLoginId"] == null)
{
alreadyMemberLabel.Visible = true;
SignInButton.Visible = true;
forgotdButton.Visible = true;
passwordLabel.Visible = true;
passwordTextBox.Visible = true;
Right here should disable visibility for "login_pop" a tags
}
Html:
<span style="width:32%; float:right;">
<div class="panel">
Log In
Sign Up
<span style="width:32%; float:right;">
<asp:Button ID="forgotdButton" CssClass="btn-link forgotPass" runat="server" Height="25px" Text="Forgot Password?"
onclick="forgotdButton_Click" Width="135px" />
</span>
</div>
Maybe there is a way to enable/disable through id?
Thanks you
Firstly, you have two same IDs on different elements (login_pop) they should be unique.
Second, you can make the <a> tag a server component and that way you can access it from your code-behind:
HTML
Log In
C#
login_pop.Disabled = true;
First off, you will not be able to do anything, in code-behind, to the anchor tag if you do not add runat="server" to the anchor element, like this:
Log In
Once you do that then you will be able to modify the attributes of the anchor tag like this:
In code-behind, this will disable the link:
login_pop.Atributes["disabled"] = "disabled";
Add both an anchor and a label control. Set the visibility property of the label to none. In order to disable the anchor, use css to hide the anchor and set the visibility property of the label.
on your code behind, doing something like this works too.
aTag.HRef = "";
I am using this div inside a repeater.
<div class="view" id="View">
I want this div control in asp.net c# code. This is my code now:
HtmlGenericControl h3name = null;
h3name = (HtmlGenericControl)RepeaterView2.Items[count].FindControl("View");
h3name.Style.Add("width", CHeight.ToString());
But I did not get the control. How can I solve this problem?
HtmlGenericControl defines the methods, properties, and events for all HTML server control elements not represented by a specific .NET Framework class.
So if its a server control you can simply use:
HtmlGenericControl sample= e.Item.FindControl("YOURDIVNAME") as HtmlGenericControl;
and also add runet="server" to your div.
First add a runat server in your div
<div class="view" id="View" runat="server">
now in item bound event of your repeater find it like
HtmlGenericControl sample= e.Item.FindControl("View") as HtmlGenericControl
Your div must be with runat = "server" attribute.
I want to enclose listbox inside a DIV tag in the code behind file using C#.I am adding all the required attributes and adding the list box as below:
Controls.Add(listBox);
I want the generated listbox to be enclosed with in a div. Please suggest how this can be done.
Thanks in advance.
If the div isn't specified in the form then it can be created in the code behind using the HtmlGeneric class:
HtmlGenericControl myDiv = new HtmlGenericControl { TagName = "div" };
myDiv.Controls.Add(listBox);
this.form1.Controls.Add(myDiv);
Otherwise if the div is already in the HTML just add an id and the runat="server" attibute and add it direclty
HTML:
<div id="myDiv" runat="server"></div>
code behind:
myDiv.Controls.Add(listBox);
I'm trying to select an element from my webpage...
I have inserted a control into my page and i need to set some values an element inside the control at pageload from c# code.. The thing is, as soon as I insert the control into the page... A prefix is appended to the id name... Because of that new name, my css definition won't be appended...
Is there any way to access this element from C# without the need to make it an Id?
Edit: To clarify what Im trying to do here. Im trying to make a generic control, which gets a width and height set to it's parameters. I need to set this manually to the element by adding a style attribute. I can't make the element an id, because this will stop the possibility of making it generic.
This is whats inside of the control... the fact is, I need the imageRotatorDiv to be a class instead of an id. Otherwise i can't use multiple image rotators on one page.
But how can I select a class in a page from c# code? Is it possible?
<div id="imageRotatorDiv" runat="server">
<div class="imageRotator">
<asp:Repeater ID="rprImages" runat="server">
<ItemTemplate>
<asp:Image ID="imgItem" runat="server" />
</ItemTemplate>
</asp:Repeater>
</div>
</div>
you can define your style to a class name instead of id.
<asp:TextBox ID="MyText" CssClass="someclass" runat="server" />
html output
<input type="text" id="Something_MyText" class="someclass" />
css
.someclass { border:solid 1px red; }
In JQuery :
$("div[id$=MyDiv]").addClass("myDiv")
And you just need to define the myDiv CSS class. Or, to modify directly the style :
$("div[id$=MyDiv]").css("font-size", "14px");
JQuery details