Calendar.js fills textbox but ASP.net reads the textbox empty - javascript

I have a text box that is filled in with a date based on the Calendar.js file that I use (can be found at http://www.mattkruse.com/javascript/calendarpopup/source.html)
The user clicks on the image button, which pops open a calendar and then fills the textbox.
It clearly works when I use it; however, when I debug my VB.net coding in Visual Studios the textbox shows empty:
Any suggestions why this is happening? I will need to read the string in the textbox later. I need to somehow convert the text that is filled from the Calander.js file and save it as a string inside the textbox.
<script type="text/javascript" id="js1">
var cal1 = new CalendarPopup();
</script>
HTML:
<td style="padding-top:20px; padding-left:15px;">
<asp:TextBox runat="server" id ="CERT_AGENCY_EXP1" Cssclass="fieldrequired" name="Agency1 Date Txt" size="10" maxlength="10" BackColor="#CCCCCC" ReadOnly="True" TabIndex="40"/>
<asp:ImageButton name="anchor1" id="anchor1" runat="server" style="padding-top:30px; float:left;" value=""/>
<img src="Images/calendar.png" value=""
onClick="cal1.select(document.forms[0].CERT_AGENCY_EXP1,'anchor1','MM/dd/yyyy'); return false;" title="cal1.select(document.forms[0].CERT_AGENCY_EXP1,'anchor1','MM/dd/yyyy'); return false;" name="anchor1" id="a1" />
</td>

Your Textbox (CERT_AGENCY_EXP1) is marked as ReadOnly. Remove that attribute and you will see the changes after the postback.
If you still want to keep the Textbox as ReadOnly, but still get the modified values do this:
CERT_AGENCY_EXP1.Attributes.Add("readonly", "readonly")

Related

Copying text from one text box to another using java script

I am hoping to get this fixed, so I have a textbox that's for initials and I want to copy that to the next 26 initial boxes so it's a bit easier for the user.
I want to do this on the Client-Side so I don't use up the performance on the server-side.
The issue I am having is that whenever I call the function that's supposed to copy the text over, somehow disables the textbox, I am unable to type anything in the textbox. Please see the code below, please let me know where I am going wrong!
<script type="text/javascript">
function copyText() {
var UI = document.getElementById("txtinitialOriginal").value;
document.getElementById("initial1").innerHTML = UI;
}
</script>
<input type="text" onkeypress="copyText(); return false" runat="server" id="txtinitialOriginal" style="font-size:20px" />
<asp:TextBox ID="initial1" placeholder="Initial Here" style="float:right" runat="server"></asp:TextBox>
What am I doing wrong?
Using InnerHtml will not set the value of a text box. InnerHTML replaces the HTML inside of the input.
Try setting the textbox with this value
document.getElementById("initial1").value = UI;
or
document.getElementById("<%= initial1.ClientID %>").value = UI;
Edit:
Your textbox is disabled because you have
onkeypress="copyText(); return false"
you need to return true

How to make lebel Invisible / Visible based on the Input given in the Search TextBox?

I'm searching names using a text box which are auto fillable. When I enter the name other than the list of auto fillable one's, I need to display a label dynamically like "Please Enter a Valid Name" like that. If I remove my wrong entry in the test box, then label should be invisible.
<asp:TextBox ID="tbName" caption="Enter Name" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ID="UIRequiredFieldValidatorName"
ControlToValidate="tbName" />
<asp:Button ID="UIButtonGo" runat="server" Text="Search" />
<asp:Label ID="UILabelSearch" runat="server"></asp:Label>
</p>
Please let me know the possible ways for this one. Thanks
You should try to do this in JavaScript. Handle the onchange event and check textbox value against the auto fillable values. In your code add tbName.properties.add("onchange","validatorMethod(this);");. In JavaScript file add:

detepicker inside TextBox not working on some aspx pages

I implemented a datepicker inside my web forms application.
I tested it on one form, and it was working. The code of the TextBox was:
<asp:TextBox runat="server" class="fieldset__input js__datepicker picker__input" type="text" id="TbDate" aria-haspopup="true" aria-expanded="false" aria-readonly="false" />
I tried to add the same textbox to another form but it wasn't triggering.
The other form had the same master page. I copied all the code aspx from the first form to the new one and it was working.
I tried deleting one line at a time to see why the datepicker was working with this code, and found that this line is needed to enable it:
<asp:TextBox runat="server" ID="tbEmail" CssClass="form-control" TextMode="SingleLine" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbEmail" ErrorMessage="The username/email field is required."/>
I want the datepicker to open when i click on the tbDate TextBox, but it only works if the RequiredFieldValidator for the TextBox tbEmail is present. If i delete the validator, the datepicker won't open on the tbDate TextBox. The Validator checks if the input of tbDate is an email format, so there is no connection to the tbDate TextBox.
Also, i tried to delete the other TextBox, and attach the fieldValidator to the tbDate TextBox, and it also works.
I don't understand how this RequiredFieldValidator is helping the datepicker to open, especially inside another textbox?
Understanding this would help me implementing it on other forms.
Thank You!
Not sure which datepicker plugin you are using but the markup for the datepickers are not the same.
<asp:TextBox runat="server" class="fieldset__input js__datepicker picker__input" type="text" id="TbDate" aria-haspopup="true" aria-expanded="false" aria-readonly="false" />
is not the same as
<asp:TextBox runat="server" ID="tbEmail" CssClass="form-control" TextMode="SingleLine" />
you are missing the classes fieldset__input js__datepicker picker__input in the second datepicker which might be selectors for the JS script that's initializing the datepicker. Try adding that and see if it works without the RequiredFieldValidator.

getting control ID inside repeater by Jquery

I have Entries I want to comment on them . So I created a Repeater with a TextBox and a
Button inside it . How can I get the id of the button and textbox for specific row by
Jquery ?
<ASP:REPEATER runat="server">
<ItemTemplate>
...
// Entries: bind data from DB
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" />
</ItemTemplate>
</ASP:REPEATER>
Thanks .
Your big problem is that your asp repeater control is going to generate ids like this ct100_repeater_txt1 which isn't going to help you get that comment associated with its corresponding db row
The common way I have found to accomplish this (which is a pretty standard way I believe) is to assign the elements id with the row id from the database, or if you have no control over the id, to create a custom attribute.
Pseudo code I have used looks something like this: (I'll try and make it language/platform agnostic so you can learn the concept, as opposed to only the language)
<repeater template>
<textbox id="txt1" dbid='<% eval database id>'/>
<button id="btn1" dbid='<% eval database id>'/>
</repeater template>
that should generate code that looks like:
<input type="textbox" value="" id="ct100_txt1" dbid="14" />
<input type="button value="submit" id="ct100_btn1" dbid="14" />
<input type="textbox" value="" id="ct100_txt2" dbid="12" />
<input type="button value="submit" id="ct100_btn2" dbid="12" />
<input type="textbox" value="" id="ct100_txt3" dbid="39" />
<input type="button value="submit" id="ct100_btn3" dbid="39" />
Then in whatever language you want you can read from that attribute:
Button.Click{
get attribute dbid of button clicked;
save text of textbox of same dbid to a database;
}
Many cheers! Hope that works for ya
EDIT
In response the the comment "where do id save the dbid?!" I'm assuming in a database :) How should you save it? There are lots of ways. Here's one you could try with jquery:
create a javascript function to save answers that takes a parameter. when you bind the dbid to the control, bind it into an onclick function and pass that id to the function. The function then gets the text where the dbid matches and saves the comment and id to a database.
<textbox dbid="14" />
<input onclick="doStuff(14)" />
<script>
function doStuff(var id){
var comment = $('textbox[dbid=id]').value();
ajax(your url and arguments);
};
</script>
Without more information this is the best I can offer you:
for html like this (which is how asp.net will render your button/textbox):
<div id="row1"><button type="button">Click Me!</button><input type="text" name="tb_info" /></div>
<div id="row2"><button type="button">Click Me again!</button><input type="text" name="tb_info" /></div>
You could select the button and textbox for specific row by using the following jQuery:
$("#row1 > button, #row1 > input")

How can i check a radio button by clicking on asp text field using javascript

Hi
While working on asp, i want if i click on my asp text field, a radio button should be checked, but i dont find any onClick event available for asp text field, and if i use onchange, it is from the server end, i want this situation without page refresh, just like we do in html fields using javascript, please help!!!
Try this one:
HTML:
<asp:TextBox ID="txtSelect" runat="server" Width="200px" Text="Click here"> </asp:TextBox>
<br />
<asp:RadioButton ID="radCheck" runat="server" />
JQUERY:
$("#txtSelect").click(function(){
$("#radCheck").attr("checked",true);
});
OnFocus is probably the event I would use.
You can use Ajax if you don't wanna refresh the page

Categories