asp:TextBox add data attribute data-emojiable="true" - c#

I want add smiles to my asp:TextBox. I find project at Git Hub [https://github.com/one-signal/emoji-picker][1]
But in an example they used html tag - input, but I need to use asp:TextBox. And when I add all as on this site, it does not work.
Here they works example
<p class="lead emoji-picker-container">
<input data-emojiable="true">
</p>
And here my example that doesn't work
<p class="lead emoji-picker-container">
<asp:TextBox ID="txtSubject" runat="server" data-emojiable="true" ></asp:TextBox>
</p>

You can do following on server side code to add attribute.Check for css and js files as well.
txtSubject.Attributes.Add("data-emojiable","true");

Related

asp.net can't take the text of input text

This is my aspx
<p>Date: <input type="text" id="datepicker" >
<asp:Button id="BookingForDate" runat="server" OnClick="BookingForDate_Click" Text="Search"/> </p>
<table id="DateBookingTable" runat="server" style="visibility:hidden">
<tr><th>ID</th><th>PlanTime</th></tr>
</table>
on my code in c# I can't see datepicker
why?
note please that i can take all the controllers from id except this one.
I already tried restart the visual studio
You have 2 options
add runat="server" to the input
<input type="text" id="datepicker" runat="server" />
or create an TextBox
<asp:TextBox runat="server" id="datepicker"></asp:TextBox>
You should add
runat="server"
to your input. No you are using an html control and not an asp.net server side control. Hence you can't access the value of the textbox the way you want.
So try the following and then you will be able to access the value of your textbox:
<asp:TextBox id="datepicker" runat="server"/>
Then in your code behind class you can access the value of this textbox
datepicker.Text
Another approach, as I pointed initially, it would be the following:
<input type="text" id="datepicker" runat="server">
You forgot to add the runat-attribute to your input-tag. Try this:
<input type="text" id="datepicker" runat="server">
With that change, you should be able to access the element from code behind
See MSDN
You have not given name to your control and also add runat="server"
<input type="text" id="datepicker" runat="server" name='datepicker' />

How to retrieve HTML control values which are placed in contentPlaceHolder in code behind file?

I've designed a web site. In that web site I used master page for my web page . And in that web page I've placed HTML controls which are in the content place holder. I want to retrieve values of the HTML control in the code behind file. How to do this?
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div>
<span>
<select id="Select1">
<option value="1">Low</option>
<option value="2">Medium</option>
<option value="3">High</option>
<option value="4">Not Assigned</option>
</select></span>
<span>
<input id="Text1" type="text" /></span>
<span>
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
</span>
</div>
</asp:Content>
I want to retrieve the HTML control value on the click event of the Button1.
As TBohnen.jnr says, you can mark them as runat="server".
If you don't want to do that then you can use Request.Form["idOfInput"], but that's not generally recommended when using WebForms.
Mark them as runat="server" on the aspx page and give them an ID and you should see them in the code behind
****Edit****
You can alternatively just use an ajax call either via web method or do a seperate postback to send only the data you want if you are worried about performance.
Have a look at this article.

Can't put a inline tag inside of a html input tag

I have a input tag like:
<input src="..." title="<%= SomeResource.Label1 %>" />
It is not rending the text, it is rendering the actual value in the title attribute:
<%= SomeResource.SoeLabelInMyResourceFile%>
I tried single quotes and no change, what am i doing wrong?
It is suppose to render the title attribute as:
title="some text value stored in the resource file"
So the issue is the server tags are not being rendered, rather it is thinking that is plain text I want to display for the value of the title attribute.
UPDATE
The text renders just fine if I do this:
<td>
<%= SomeResource.Label1 %>
<input src="..." title="" />
</td>
But if I put the tags inside the title attribute, I get the error.
UPDATE
1 Create service folder App_GlobalResources (Project -> Add -> ASP.NET Folder)
2 Move resx-files to this folder
3 Get access to data:
In addition to programmatic access, ASP.NET 2.0 also introduces declarative syntax you can use to bind a named string to a property of a page or control. The syntax involves using the dollar sign ($) followed by the Resources namespace, the name of the resource file and the name of the string [see Resources and Localization in ASP.NET 2.0]
<asp:Literal runat="server" Text="<%$ Resources:Resource1, String1 %>" />
<input runat="server" type="text" value="<%$ Resources:Resource1, String1 %>" />
It works fine!
Try it:
<input src="..." title="<%$ Resources:SomeResource, Label1 %>" />
or
<input runat="server" src="..." title="<%$ Resources:SomeResource, Label1 %>" />
Can you make it work with an <asp:textbox> instead?
Try using GetLocalResourceObject()
<input src="..." title="<%= GetLocalResourceObject('SomeResource.Label1') %>" />
May be your input is marked as runat="server" ?
If you'll remove runat="server" title="<%= SomeResource.Label1.Text %>" gonna be work as expected.

ASP.Net: ClientID not correct in code-behind of a user control

The following code does not work. The markup is in a User Control and I suppose that's why ClientID returns the wrong prefix for the TextBox id.
Markup:
<INPUT id="txtName" runat="server" maxlength="50" style="WIDTH:100px">
<INPUT type="button" value="Find Your Doctor" id="btnFind" runat="server"
style="MARGIN-LEFT:10px;WIDTH:130px">
Code-Behind:
btnFind.Attributes.Add("onClick",string.Format("DoctorLink
('{0}',document.getElementById('{1}').value,{2});",
row["ZipCode"],
txtName.ClientID));
Results in browser:
<input name="DoctorsMainArea1$ctl01$txtName" type="text"
id="DoctorsMainArea1_ctl01_txtName" maxlength="50" style="WIDTH:100px" />
<input name="DoctorsMainArea1$ctl01$btnFind" type="button"
id="DoctorsMainArea1_ctl01_btnFind" value="Find Your Doctor" style="MARGIN-
LEFT:10px;WIDTH:130px" onClick="PrepareDoctorLink('90210',
document.getElementById('DoctorsMainArea1_ctl00_txtName').value);" />
As you can see, the parameter for the JavaScript call is DoctorsMainArea1_ctl00_txtName, but the actual id of the input element is DoctorsMainArea1_ctl01_txtName.
Any idea how to fix this? jQuery? I am not so much interested in an explanation of what's going on (maybe there is another control on this page that is interfering), but a more robust way to solve the problem.
I don't know which asp.net version you are using but in 4.0 you can declare inside any server control ClientIDMode="static" and it will give you the exact id in browser.
Example:
<asp:Textbox id="txtName" runat="server" ClientIdMode="static"/>
Others are predictable, inherit and it can be used with ClientIdRowsuffix.Can be used at page level and even on master pages and even in web.config file.
Example on web.config file:
<system.web>
<Pages clientIDMode="predictable"/>
other system web properties
</system.web>
Watched Craig shoemaker's Video at tekpub, you can also read more about it at Rick's bloglink text. It's pretty cool tho.
You should try moving the code that adds the onclick attribute to the button in the PreRender event (or OnPreRender override) in your page or user-control. That should probably get the ClientID right.
A fast solution:
btnFind.Attributes.Add("onClick",string.Format("DoctorLink
('{0}',document.getElementById('{1}').value,{2});",
row["ZipCode"],
"DoctorsMainArea1_ctl01_" + txtName.ClientID));
This happens because you have a content placeholder in your page somewhere.
another solution:
html tag:
<input type="text" name="txtName" id="txtName" />
code-bind:
string txtName_value = Request.Forms["txtName"];
and you can get the value
just use the html control.

Form fields not retained on postback

I'm developing a website using EPiServer. I have a form which submits to itself.
On submit, I check if there are any fields missing. If yes, then error message is shown.
The problem is that my fields are reset when submitted.
I could check this using jQuery, but I'm not. I'm cheking this from code behind.
I've tried setting EnableViewState=true sevceral places, but no luck.
Here's part of my code:
<asp:Content ID="Content3" ContentPlaceHolderID="RightContentPlaceHolder" runat="server">
<asp:Panel ID="panelComplaint" runat="server">
<li>
<h3>Postnummer*</h3>
<input id="senderPostCode" name="postCode" type="text" size="20" enableviewstate="true" />
<asp:Label runat="server" id="lblPostCode" CssClass="missingField" Text="Mangler tekst" Visible="false" />
</li>
<li>
<h3>Post sted*</h3>
<input id="senderCity" name="city" type="text" size="100" />
<asp:Label runat="server" id="lblCity" CssClass="missingField" Text="Mangler tekst" Visible="false" />
</li>
<li>
<div class="spacer10px"></div>
<button type="submit" name="Send" >Send me</button>
</li>
</asp:Panel>
</asp:Content>
What do I need to do, in order to retain form fields?
Have you tried adding runat="server" to the input fields? As far as I'm aware, this is needed to ensure that asp.net round-trips data properly. I'm not sure if there's anything specific to EPiServer that would make that differ.
The enableviewstate attribute, unless it's specific to EPiServer, won't actually be doing anything.
If having the ID mashed up by ASP.net is a problem, consider upgrading to .NET 4.0, if you can, as this provides ways for you to control how the ID's are modified. If not, you could try placing a friendly translation into the page that you can then access via JQuery, for example:
<script language="javascript" type="text/javascript">
function getSenderPostCode() { return eval('<%=senderPostCode.ClientID%>'); }
var senderPostCodeField = JQuery('#getsenderPostCode');
alert(senderPostCodeField.length());
</script>
That said, having "getSenderPostCode()" to reference would mean that you could probably skip the step with JQuery of getting a reference to it, so the following would work:
alert(getSenderPostCode().length();
By adding runat="server" to your controls you then wouldn't need to use Request.Form["senderPostCode"].ToString() to access the content of that field, you could instead access it directly:
var contentOfSenderPostCode = senderPostCode.Value.ToString();

Categories

Resources