I have list of images stored in sql database.
i try to add it dynamic at run time .
i use "InnerHtml"
i create dive tag and want to add the image list in the div tag
HTML:
<div runat=server class="ws_images" id="List_Slide">
C#
List_Slide.InnerHtml = "<li><img src=data1/images/31.jpg alt=31 title=31 id=wows1_0/></li>"
can you help me ?
It looks like you are using ASP.NET web forms.
What you can do is drop a asp:PlaceHolder control onto your page then add Literal controls in there that contain your image HTML code.
<asp:PlaceHolder id="ImagePlaceHolder" runat="server"/>
..
..
In code behind:
var literal = new LiteralControl("<li><img src=data1/images/31.jpg alt=31 title=31 id=wows1_0/></li>");
ImagePlaceHolder.Controls.Add(literal);
PlaceHolder does not render any HTML tags so if you want you can put your div tag inside the LiteralControl.
Related
I have an aspx page with 2 panels (C# code-behind), (Panel1 & Panel2). Inside Panel1 I load an HTML page. Inside Panel2 there is an aspx textbox. I want to select some text of the HTML page in Panel1 and send it to the textbox of Panel2. Would you please say how to do it?
If you know what part you want to select, assign it an ID and a runat="server" value, then you will be able to access it from the code.
For example:
If you have something like this in your HTML:
<div id="divForCode" runat="server"></div>
Then you can access the contents of the div in code-behind using
divForCode.InnerHTML;
and
divForCode.InnerText;
So all you would need to do is send it to the textbox (myTextBox.Text = divForCode.InnerHTML; or myTextBox.Text = divForCode.InnerHtml;)
Sorry I had to post this as an answer, I don't have enough reputation to comment.
I'm having a problem while creating dynamically a web page in ASP.NET (C#).
I need to insert multiple form tags in that page, I know that I can't put
more than one with runat="server" attribute and I don't need it.
I want to place them from C# (one for each element I've got to manage), without the runat attribute but the HtmlForm object
that I use for insert the form adds the runat attribute automatically and I can't remove it
(tried with form.Attributes.Remove("runat"))
If I use a simple string like:
"<form id="someID" method="POST" action=""></form>"
and I add it multiple times into my div it works.
The point is that I don't want to insert ALL my HTML objects writing them in a string
and add it with InnerHTML method. I'm looking for an object that manage a Form without
the runat attribute or a way to remove that from HtmlForm.
A user control is probably the cleanest solution but you can add an HtmlGenericControl instead of a HtmlForm object which isn't bound to any specific attributes.
Dim ctrl As New HtmlGenericControl("form")
ctrl.Attributes.Add("id", "someID")
ctrl.Attributes.Add("method", "POST")
ctrl.Attributes.Add("action", "")
OuterDivContainer.Controls.Add(ctrl)
If you want to add controls dynamically to a page and make the web page render them as pure html, instead of rendering asp:Controls you can use the Literal control. Check this link or this one
I need to export the webpage to PDF for that am reading all the content of that file and writing that content in to the PDF file.
Please refer below dynamic content in div tag
<div ng-app="criteriaApp">
<div ng-include src="'#Url.Content("~/template.html")'"></div>
</div>
template.html content will be modified dynamically in jquery and displayed in view.
So whenvever am inpsecting the webpage through developer tools i can able to see the content
like
<div ng-app="criteriaApp">
<div ng-include src="'#Url.Content("~/template.html")'">
<div>.......</div>
</div>
</div>
but getting the content through File.ReadAllText doesn't give original DOM elements. it gives the page source code only (i.e. getting viewPage Source by right clicking the page)
string contents = File.ReadAllText(path);
i need to get the dynamic contents of div through above code ?
Note : File.ReadAllText returns page source code only. not all DOM nodes generated dynamically.
The dynamic content is there in DOM. how can i get DOM code for particular div in C# ?
how can i acheive this ?
Thanks,
Siva
To get the dynamic contents of div through your html code, you need to use a engine like webkit to generate DOM. If you need to export your page as pdf, you should look at razor pdf or rotativa.
I need to append a div (with is content), after all tags with a specific css class (or data- tag) in code behind of asp.net c#.
Someone can help me? Basically it should work as "append" in jquery. I searched online but could not find anything, especially to "append" to a tag with a specific CSS class.
Thank you.
You can add a diva as an html generic control from the code behind
for example i have a div like this
<div id="test" runat="server">Some Content</div>
As i specified runat server it will be available there and i can add contents like this
HtmlGenericControl div= HtmlGenericControl();
div.TagName = "div"; //specify the tag here
//then specify the attributes
div.Attributes["height"] = "100%";
div.Attributes["width"] = "100%";
div.Attributes["class"] = "someclass";
div.Attributes["id"] = "someid";
test.Controls.Add(div);
When building a custom control, how would you access the content between the opening and closing control tags?
<my:tag runat="server">
<p>...markup</p>...
</my:tag>
I am currently successfully using the Render method to output arbitrary markeup, but cannot seem to find out how to access the contained markup.
Take a look at this.Controls. This article :
http://msdn.microsoft.com/en-us/library/system.web.ui.control.controls(VS.71).aspx states "On an ASP.NET page, when controls are added declaratively between the opening and closing tags of a server control, ASP.NET automatically adds the controls to the containing server control's ControlCollection. "
As far as I understand, if you have
<yourcode:yourcontrol id="asdf" runat="server">
<p id="innerP" runat="server">Text here</p>
</yourcode:yourcontrol>
Then it would be possible to call this.FindControl("innerP").text="Other text here, since the P tag is generated on the server side.
However, if you do not have the runat="server" set on the P element:
<yourcode:yourcontrol id="asdf" runat="server">
<p id="innerP">Text here</p>
</yourcode:yourcontrol>
then you only can only find it through this.controls[0] since all the content will be rendered into a single Literal control.
I think you want to do this:
<my:tag runtat="server">
<p><asp:Label id="markupLabel" runat="server"/></p>
</my:tag>
And from the code-behind
markupLabel.text = "Foo";
If you add an ID to the my:tag tag, you should be able to access the controls inside of it using the .Controls collection of the tag.