Wrapping Text in a Button Text Field - c#

I have been trying to wrap text in the Text Field of the asp button control.
Suppose I have a long file name which is kept in the text field of text box. Now if I do not set the width of the button it can grow to 200px. But I want the width to be 100 px and the text to be wrapped in the text field or I can set the text to be multi-line.

Replace space with
Try following code
<asp:Button ID="Button1" runat="server" Text="Button
Button
Button
Button" Width="100px" Height="200px" />

One link from comment leads to this solution:
<asp:Button ID="btnSubmitBatch" runat="server" Text="Submit&#10Batch" Font-Bold="true" />
But this doesn't work in Opera.

Set width of the button to 100px, and increase the height of the button.
If required, you can also decrease the padding of the button, so that the text fits-in.
Update:
What you can do then is a bit tricky, but works for me.
Make a div styled like a button, put "width:100px;height:auto" in CSS. And make the real button display:none in CSS.
Write a click event for the div, and click the real button manually from there.
$("#divButton").click(function () {
$("#btnReal").click();
});
Hope it helps :)

c#:(in the code behind on cs page)
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine("Text1");
sb.AppendLine("Text2");
BtnID.Text = sb.ToString();

You need to use CSS to achieve this.
<asp:Button ID="btn" runat="server" Text="This is some really long text that I want inside the button" CssClass="wrap" />
And now the CSS
<style type="text/css">
.wrap
{
white-space:normal;
}

Related

Error Message: The server tag is not well formed

When I use the below code, this error is shown:
The server tag is not well formed
Markup:
<asp:Button ID="AddProduct" runat="server"
style="color:white" Text= "Add Product"
onclick="AddProduct_Click"
BackColor="Black"
TextBox1.text="string.Empty" TextBox2.text="string.Empty"
TextBox3.text="string.Empty" TextBox4.text="string.Empty" />
You can not assign another textbox's text in one button.
<asp:Button ID = "AddProduct" runat = "server" style ="color:white" Text= "Add Product"
onclick= "AddProduct_Click" BackColor = "Black"
TextBox1.text = "string.Empty" />
if you want to change those on click of the button then create click event handler in the back end and then set those properties their. Your code has registered that handler as named AddProduct_Click.
Try putting textbox texts inside the AddProduct_Click event handler in the code behind file.
For instance,
TextBox1.Text="";
TextBox2.Text="";
TextBox3.Text="";
TextBox4.Text="";
You need not add these expression in the button tag. Make sure that runat="server" has been given in the button tag.
Hope this will resolve your problem.

Aligning html inputs on same line 2

I have the same behavior from many similar questions here.
But I tried anything and nothing happens to me.
I have 2 html controls. One anchor tag and a input button.
I applied vertical-align:top; float:right; display:inline-block; independently and together and nothing happens.
When I click on Close, I see a shadow like a button! I want them inline both controls
At the end of table I incluided a Div like this.
<div style="float:right;">
<asp:Button ID="btnInput" runat="server" Text="Add selected"></asp:Button>Close
</div>
You need to set a width for each element when you make them display:inline-block, otherwise they default to 100%.
Here is a jsFiddle with the closest equivalent markup I could make. (asp buttons don't work)
As Dolchio said, every element must have display: inline-block for this to work. Note that your float:right will not achieve anything helpful in this scenario.
Try adding the CssClass attribute to the asp button and styling that class.
So it would look like <asp:Button ID="btnInput" runat="server" CssClass="myButton" Text="Add selected"></asp> and in your css myButton{display:inline-block,vertical-align: top, width: 200px substitute width for whatever the width of the button is (not entirely familiar with asp buttons and their implied widths).

Trouble checking checkbox

I have received several reports from people not being able to register on my website due to them not being able to check a checkbox stating they agree to the Terms of Use. Basically, once the checkbox is checked a button is enabled to allow one to continue with registration.
I've tried myself and a lot of the time, clicking on the actual checkbox doesn't do anything but clicking on the associated label usually does. I've given that as the workaround but I'd really like to have clicking on the actual checkbox work all of the time.
The registration page is: http://www.lonelycache.com/Account/GeocachingAuth.aspx
The page form has the following for the checkbox (formatted for readability):
<asp:CheckBox ID="AgreeTOUCheckBox"
AutoPostBack="true"
runat="server" Text=" I have read and agree to the"
OnCheckedChanged="AgreeTOUCheckBox_OnCheckChanged" />
The generated html is (formatted for readability):
<input id="MainContent_AgreeTOUCheckBox" type="checkbox"
name="ctl00$MainContent$AgreeTOUCheckBox"
onclick="javascript:setTimeout('__doPostBack(\'ctl00$MainContent$AgreeTOUCheckBox\',\'\')', 0)"
/>
<label for="MainContent_AgreeTOUCheckBox"> I have read and agree to the</label>
Any ideas on what I might do to get this to work consistently?
Your checkbox is working fine, it's just hidden behind another panel. If you click and drag below the checkbox to highlight the page itself, you can see your left footprint panel is hiding most of the checkbox.
Try clicking just the very right edge of the checkbox and it will work.
It's probably as easy as adjusting your style like so:
<div style="padding-left:10px">
<asp:CheckBox ID="AgreeTOUCheckBox"
AutoPostBack="true"
runat="server" Text=" I have read and agree to the"
OnCheckedChanged="AgreeTOUCheckBox_OnCheckChanged" />
</div>
The same is true of your Authorize button. Try clicking the very left of that and it won't work.
Let me know if that does it for you.
This problem has nothing to do with ASP.NET. I've checked your website and you have a DIV (id: boots) that is sitting on top of the majority of the checkbox (it displays the boots image on the left as it's background image).
If you set the width of that div to be 180px rather than 200px, it should solve your problem,
I tested your site. I can't check either.
According to what I tested, your checkbox is just to enable the button. If so, you can just simply use jQuery to do that.
Here is the sample:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#<%= AgreeTOUCheckBox.ClientID %>').click(function () {
if ($('#<%= AgreeTOUCheckBox.ClientID %>').attr('checked')) {
$('#<%= AuthorizeButton.ClientID %>').removeAttr("disabled");
} else {
$('#<%= AuthorizeButton.ClientID %>').prop("disabled", "disabled");
}
});
});
</script>
<asp:CheckBox ID="AgreeTOUCheckBox" runat="server"
Text=" I have read and agree to the" />
<asp:Button runat="server" ID="AuthorizeButton"
Text="Authorize" Enabled="False"/>

RadSpell display redlines

I have a multiline checkbox. I want to use RadSpell.
But everytime I insert text on the textbox it doesn't display red lines.
How can i do this?
here is my code.
<telerik:RadTextBox ID="textbox1" runat="server" TextMode="MultiLine" Rows="4"
Columns="51" Width="401px" Font-Size="10" Font-Names="Calibri" />
<telerik:radspell id="RadSpell1" runat="server" DictionaryLanguage="English"
controltocheck="textbox1" spellcheckprovider="PhoneticProvider"
supportedlanguages="en-US,English" ButtonType="None"/>
NOTE: No buttons needed.
I just want to show all the words that are misspelled.
That's a browser feature - inline spellchecking. All modern browsers have it. Well, IE doesn't, but why should we call it modern? ;-)
What RadSpell can do for you is a popup with suggestions and information.
EDIT: Forgot to mention you can trigger RadSpell's check programmatically: http://www.telerik.com/help/aspnet-ajax/spell-client-side-api.html. Look for the startSpellCheck() method. For example in the onblur event.

get asp:textbox value in client side using javascript function doesn't work

This code doesn't display the value, I don't know why?
I have server control:
<asp:TextBox ID="txtTest" runat="server" Visible="false" TextMode="MultiLine"
Rows="3" Columns="23" CssClass="white-scroll" />
in javascript function:
var eventText = document.getElementById('<%=txtTest.ClientID%>').value;
alert (eventText);
I enter text then click on button that call the javascript function, but the alert box doesn't display the entered text.
EDIT: when I initialize the text with Text="some text", it is displayed in alert, I want to enter text in client side and get the value of it in the Javascript function.
Thanks
Using label or textbox visible set false so it can access the value in JavaScript
Sol
1)
Make a div and set style="display:none;" so label is not display at UI(browser) but value can access in JavaScript.
This is because you server Control is called "txtTest" not "txtEventDescription"
change your javascript function to :
var eventText = document.getElementById('<%=txtTest.ClientID%>').value;
alert (eventText);
EDIT: ok, I see you've now changed the post to show the code and renamed the js control, so above is no longer relevant (for those who are confused by my answer) :-)
The problem is the Visible="false" - this control will not render into the client and will therefore not be accessible via javascript (as the HTML element does not exist client side)
So, hide the element using CSS and then call alert on it. Sample snippet
CSS
.hide-element {
display: none;
}
HTML Markup
<asp:TextBox ID="txtTest" runat="server"
Columns="23"
CssClass="white-scroll hide-element"
Rows="3"
TextMode="MultiLine"/>
JavaScript
var eventText = document.getElementById('<%=txtTest.ClientID%>').value;
alert (eventText);
This way you will definitely get an alert.
You alert is empty because you have not set the property Text for your asp:Textbox
Make it Visible="true" to your textbox and than test.
<asp:TextBox ID="txtTest" runat="server" TextMode="MultiLine"
Rows="3" Columns="23" CssClass="white-scroll" />
if "txtTest" textbox has visible="false" in that case its not render on html code on client machine and if it hasn't on client's html code then how javascript calls this textbox. Because when javascript search this textbox by its id it doesn't find and it gives an error.
you can assign any other custom attribute to the control i.e.
<asp:TextBox ID="txtTest" runat="server" Visible="false" TextMode="MultiLine"
Rows="3" Columns="23" CssClass="white-scroll"
clientID="myClientID" />
and then access control using jquery like
var txtVal = $('textbox[clientID=myClientID]').val();
hope it helps.

Categories