How to display multi line in Label? - c#

The following is the record which I am getting from the database:
"Dear:Thank you for applying to school. We have received your application to the program.As of today,we have received the following for your application:"
I am trying to put the above value into a label. My label looks like the following:
<div id="secondd" style="float:left;width:50%;background-color:#C0D5F2;">
<asp:Label id="valueIntroduction" Cssclass="labelarea" runat="server"> </asp:Label>
<div class="line"></div>
My problem is value is not getting fitted into the label. How to make it as a multi line label?
Here is the HTML that contains this div:
<div id="first" style="float:left;width:50%;background-color:#C0D5F2">
<div id="second" style="float:left;width:50%;background-color:#C0D5F2">
<div id="Introduction" style="float:left;width:100%" class="wote">
Introduction:
</div>
<div class="line"></div>
</div>
<div id="secondd" style="float:left;width:50%;background-color:#C0D5F2;">
<asp:Literal id="valueIntroduction" runat="server"> </asp:Literal>
<div class="line"></div>
</div>

If you want the text to wrap based on the in-line style of your outer <div>, you can change the <asp:label> to an <asp:literal> and use CSS to style the outer <div>.
The difference is that a Literal does not render any HTML markup, whereas a Label will be wrapped in a element. The Literal just inserts the exact text you have, letting your existing HTML and CSS do the styling.
An example of a different style would be:
Less percentage, note 20% instead of 50% for the width attribute:
<div id="secondd" style="float:left;width:20%;background-color:#C0D5F2;">
Or, use a dedicated value of pixels (denoted by the px)
<div id="secondd" style="float:left;width:150px;background-color:#C0D5F2;">
You can even indent the text, using text-indent. I suggest to google some basic CSS and just try different things out, it is the best way to learn.
You just have to play with it to see how it fits in your webpage. Once you get the hang of it, note for future reference that you can use style sheets for this stuff which will make your code cleaner and allow you to create reusable, easily editable styles for your application.

Related

Include form tag only in master page if content page not contains <form> tag?

I am using <asp:ScriptManager> and link in master page which require <Form> tag but issue is here that i have included already <form> tags in all the child content pages.
I know i just need to include <form> tag just in master page and remove from all child pages but unfortunately its not possible because there are so many content child pages which connected to this master page and also each child <form> tags contains different classes like horizental inline etc.
So i just want that i just want to include <form> tag only in master page if form tag not exist in content/child page.
If i use both in master and child/content, its showing error, its must 1 form tag.
Master page
<form id="Form2" runat="server" novalidate="" role="form" runat="server" class="form-horizontal">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<h3>Session Idle: <span id="secondsIdle"></span> seconds.</h3>
<asp:LinkButton ID="lnkFake" runat="server" />
<cc1:modalpopupextender id="mpeTimeout" behaviorid="mpeTimeout"
runat="server" popupcontrolid="pnlPopup" targetcontrolid="lnkFake"
okcontrolid="btnYes" cancelcontrolid="btnNo"
backgroundcssclass="modalBackground" onokscript="ResetSession()">
</cc1:modalpopupextender>
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
<div class="header">
Session Expiring!
</div>
<div class="body">
Your Session will expire in <span id="seconds"></span> seconds.<br />
Do you want to reset?
</div>
<div class="footer" align="right">
<asp:Button ID="btnYes" runat="server" Text="Yes" CssClass="yes" />
<asp:Button ID="btnNo" runat="server" Text="No" CssClass="no" />
</div>
</asp:Panel>
<asp:ContentPlaceHolder ID="body" runat="server">
</asp:ContentPlaceHolder>
</form>
I just want to use form tag only if not in child page. how can i tackle this situation,
Thanks,
As far as I know, the ASP.NET WebForms do not support multiple form elements with runat="server" attribute. So, there is no work around to this as it is something hard coded into the project.
Anyhow, if there are suppose a thousand child pages that also have form element with runat="server" attribute, and you are too lazy to replace all of them one by one, Then you can use Visual Studio's text replacing feature and can change the form element to a div element. For that you just need to press Ctrl + H which will open a little window on top right corner asking for the text that you want to replace and another text that you want to have instead of that. See:
Notice in the screenshot I have shared, I am selecting Current Project from the drop down menu. This will search and replace every text with <form to <div in the project.
And once it has replaced all the tags starting with <form to <div then you can modify the closing text of the form tag by replacing </form with </div. Now you only have left one page.
Now, there is only the MasterPage left that you can replace back the div to form. So, this way you are manually changing only one page.
You need to click the second button that will replace all the values. There are other options to handle the find and replace that you can use as well. But, unfortunately, you cannot have multiple form tags with runat="server" attributes on it.
PS
It won't cause problem with the designs that you have and classes such as horizontal inline will be applied to those divs instead of forms and will be rendered same as the forms were being rendered on the UI.
It is always a good approach to take a backup before modifying things in bulk or changing something that is crucial and could cause a lot mess.

How to save data from summernote into SQL DB

how are you guys?
i have asp.net webform its for adding news in the news content i would like to use summernote http://summernote.org/ Super Simple WYSIWYG editor. as a WYSIWYG editor so could some one please help me to save the data from this editor
this is my code
<div class="form-body">
<div class="form-group last">
<label class="control-label col-md-2">News Content</label>
<div class="col-md-10">
<div name="summernote" id="summernote_1"> </div>
<asp:label runat="server" text="Label" ID="news_con" ></asp:label>
</div>
</div>
</div>
i can't get the text value from the summernote
by this code
news_con.Text = Request.Form["summernote_1"];
Have you considered using a <textarea> to handle this as opposed to a <div>? Usually they are a bit easier to use with respect to storing values (as they are designed to do so) :
<textarea id="txtTest" runat="server"></textarea>
One of the ways that you might handle this would be to register an event using Summernote's available API to set the HTML content for your <textarea> element whenever focus was lost (e.g. the onblur) :
<script>
$(function () {
// Set up your summernote instance
$("#txtTest").summernote();
// When the summernote instance loses focus, update the content of your <textarea>
$("#txtTest").on('summernote.blur', function () {
$('#txtTest').html($('#txtTest').summernote('code'));
});
});
</script>
Since you are likely going to be storing HTML content within the element, you'll likely want to ensure that .NET doesn't think you are trying to exploit it. You can do this by either explicitly setting this page to ignore that process by updating the ValidateRequest property of your page :
<%# Page ... ValidateRequest = "false" %>
Or you could try simply escaping the content that is being set :
$('#txtTest').html(escape($('#txtTest').summernote('code')));

Make a Dropdownmenu with CSS

I would like to make a Dropdownmenu, but It is not that easy, because I am working with panels.
This is my menu. I've got the nav= menu and then I got a panel for the menu and one for the submenu. The submenupanel is not displayed by default.
Now I wan't a block which comes down, when I hover over the pnlMenu.
<div id="wrapper_menu">
<div id="menuicon">
<div class="menubar" id="menubar-top"></div>
<div class="menubar" id="menubar-mid"></div>
<div class="menubar" id="menubar-bottom"></div>
</div>
<nav id="menu">
<asp:Panel ID="pnlMenu" runat="server"></asp:Panel>
<asp:Panel ID="pnlSubmenu" runat="server">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</asp:Panel>
</nav>
</div>
This is my css code which I have. What I also need is a selector which changes an other div. I don't know if it is really posssible that it works like that, but isn't anything which should display the Dropdownmenu, I only wanted to look if I can select like that.
#pnlMenu .menu_link:hover #pnlSubmenu .submenu_link {
height:50px;
display:block;
}
Because I am working with the masterpage, there's code which gets generated.
This is my html code:
This will not work
#pnlMenu .menu_link:hover #pnlSubmenu .submenu_link {
height:50px;
display:block;
}
because it assumes that #pnlSubmenu is a child of .menu_link which it is not.
In fact #pnlSubmenu is a sibling of #pnlMenu so you may need to rethink the approach.
I suspect that the interactivity may need javascript given the HTML's current structure as there is no CSS selector that will allow you to affect the submenu div by hovering a link in the the first menu div

Making non-asp table invisible in behind-code

I'm working with code someone else has written that I cannot change too much for now.
It has a table defined in the html, something like this:
<table id="tblResult">
some stuff defined in here.
</table>
I would like to use the behind code to make this table and all its contents invisible, but I notice I can't address the table directly as tblResult.visible in the code behind. This makes sense to me, since this is not an asp object. Simply changing this to an asp:table doesn't work, as there's some stuff going on inside that table I prefer not to mess with. Is it possible to address that table and set visibility to false from the behindcode?
Wrap it into a <asp:PlaceHolder> amd then toggle the placeholder visibility.
Add runat='server' to the tag. The other thing you can do is wrap it around a server side tag of div, panel, etc and set them to visible='false' Something to this effect:
<div id='myDiv' runat='server'>
<table id="tblResult">
//stuff
</table>
</div>
Then in your code-behind:
this.myDiv.Visible=False;
This will now ensure your table is not visible. Again you can use div's, panels (which are just divs really), literals, placeholders, etc.
You can wrap it in a Literal:
<asp:Literal runat="server" ID="Literal1" Visible="False">
<table> ... </table>
</asp:Literal>

Turning HTML Div code into a Control

I have bunch of HTML code I am using to make rounded edge boxes on my controls. Is there a way to take this code and turn it into some kind of control or something so I do not have to keep pasting 10 lines of HTML code around everything I do?
<div id="BottomBody">
<div class="box1024" >
<div class="content1024">
<div class="top1024"></div>
<h1>My Header Information</h1>
<hr />
<p>Some text for everyone!</p>
</div>
<div class="bottom1024">
<div></div>
</div>
</div>
</div>
One additional thing to note, the number HTML tags used inside the inner most DIV will change depending on where I use it in my site. So in some cases I will only have 1 tag and 1 tag but in other cases I could have 1 tag, 1 tag, 3 tags, and a HTML table. How can I make that work?
Yes, you're thinking of a UserControl. Extract the relevant HTML out, paste it into a UserControl .ascx template.
Now in your case, you'll probably want the text to be customizable, am I right? So you'll need to replace the <h1> through </p> bit with an ASP.NET label. The resulting .ascx HTML (not counting the #Control directive) will look something like:
<div id="BottomBody">
<div class="box1024" >
<div class="content1024">
<div class="top1024"></div>
<asp:Label runat="Server" id="label1" />
</div>
<div class="bottom1024">
<div></div>
</div>
</div>
</div>
Alternatively, you could do two labels -- one for the header, one for the main text. Or even just have the header be runat="Server" itself.
Next, you'll write a little bit of code in the .ascx code-behind file to expose the label's (or labels', as the case may be) Text property. This would probably look something like:
public string Text
{
get { return label1.Text; }
set { label1.Text = value; }
}
If you're in an ASP.NET MVC world, use your Model data instead of a label, and pass in the desired display text string as the model data.
Edit
Addressing the update to the question:
One additional thing to note, the
number HTML tags used inside the inner
most DIV will change depending on
where I use it in my site. So in some
cases I will only have 1 tag and 1
tag but in other cases I could have 1
tag, 1
tag, 3 tags, and a HTML table. How can
I make that work?
The exact same technique, assuming that the content you're referring to is what's within <div class="content1024">. The Text property of a label can contain any desired arbitrary HTML, and of course you can pass any arbitrary amount of HTML as a string to the Model if you're using MVC.
Another left field approach - create a user control but use jQuery to round the corners for you:
<div class="roundcorner">
<h1>My Header Information</h1>
<hr />
<asp:Label runat="Server" id="label1" />
</div>
Issue the following in javascript:
$(document).ready(function(){
$('div.roundedcorner').corner();
});
This eliminates all your extra div's and you can still have a user control that you use at will on the server.
(I know I'm going to get in trouble for this from someone)
If its just static content you can just put it in a separate file and INCLUDE it
<!--#INCLUDE VIRTUAL="/_includes/i_yourfile.htm" -->
(File name, extension and location are arbitrary)

Categories