OnCheckedChanged not working in Asp.Net and VB (codebehind) - asp.net

I have a problem with the trigger of the OnCheckedChanged. When I click the checkbox (switch toggle), the OnCheckedChanged is not firing. I already tried many solutions like trigger it in JS part but no luck.
Below is the checkbox code:
<input type="checkbox" data-toggle="toggle" data-onstyle="info" data-offstyle="secondary" data-on="Ja" data-off="Nee" data-size="xs" runat="server"
oncheckedchanged="showProductFoto_CheckedChanged" AutoPostBack="true"
style="margin-top: -5px;" runat="server" id="showProductFoto" onchange="IncludeWithoutPhotos(this)" ClientIDMode="Static"/>

Well, then get the css working for the check box, and then you back to using the standard asp.net controls - and they are a pure joy to use, and easy to use.
So, say I have this check box:
<asp:CheckBox ID="CheckBox1"
runat="server" Text="Confirm to send email"
OnCheckedChanged="CheckBox1_CheckedChanged" >
We get this ugly thing:
so, I can see your motivation to want to dump that ugly above.
but, a check box gets renderd as a html input (type = checkbox), and also puts in a label for you.
So, you can style it anyway you want.
Say, like this:
<style>
.bigcheck input {width:28px;height:28px;cursor:pointer;
box-shadow: 5px 5px 5px grey}
.bigcheck label {position:absolute;margin-left:15px;margin-top:10px}
</style>
<asp:CheckBox ID="CheckBox1" CssClass="bigcheck"
runat="server" Text="Confirm to send email"
OnCheckedChanged="CheckBox1_CheckedChanged" />
And now we get this:
so, you still have quite much unlimited css you can apply against that check box.

Related

.net ascx control not retaining value on postback (mojoPortal)

I'm making a custom module for mojoPortal CMS which needs to allow the client to add an affiliate into the database. As far as I can tell, this requires creating a .ascx file and then installing that using the administration toolbar in the Web interface to get it to a point where I can put it into a page, as http://www.mojoportal.com/hello-world-developer-quick-start.aspx.
The form is simple enough, but the values in the text boxes just stay empty when I submit, though the file upload works fine. The code:
<asp:Label ID="Label1" runat="server" Text="Company Name" AssociatedControlID="CompanyName">
</asp:Label>
<asp:TextBox ID="CompanyName" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Company Description" AssociatedControlID="CompanyDescription"></asp:Label>
<asp:TextBox ID="CompanyDescription" TextMode="MultiLine" runat="server"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="Company Logo" AssociatedControlID="CompanyLogo"></asp:Label>
<asp:FileUpload ID="CompanyLogo" runat="server" />
<asp:Button ID="SubmitButton" runat="server" Text="Add Affiliate" />
EnableViewState for the page and the controls is enabled
The text box is not set to ReadOnly, and there is no funky JavaScript dynamically modifying elements (at least, I didn't set any).
I can work around this by using HTML elements, and get the values using Request.Form. The information is actually there, I can see it in the Request.Form, but I would have to get that by something like Request.Form[CompanyName.ClientId.Replace("_","$")] or Request.Form[6] which both seem very messy and IIRC aren't really the way things are supposed to roll in .NET. Besides, having worked until 3 last night, I really want to know what the answer is now!
Any thoughts anyone?
What I had done was not created a click event for the button, relying on the fact that it was posting to the server (like I would in PHP). Oops! When I added a click event, then the text boxes retained their value when I was within that method.

Is it possible to avoid rendering the error message from an ASP.Net validator control until the validator is evaluated as invalid?

Considering the fact that I was not able to find a single instance of someone else needing this functionality anywhere else, this might be an off the wall requirement. That said:
A website that I am working on uses several dozen different validator controls (everything from RequiredFieldValidaotrs to CustomValidators) throughout for form validation. As part of our Section 508 compliance, we have to support users who disable CSS, which is problematic because the validators render the error text to the page and use the CSS display property to hide it. When CSS is disabled all of the error messages are both visible and read by screen readers.
Short of using labels and postbacks to show and hide said labels, is there any known method for using ASP.Net validator controls with CSS disabled?
Use the Display="None" attribute on the FieldValidator control and a ValidationSummary tag to contain the messages.
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="TextBox1" /> <br />
<asp:TextBox runat="server" ID="TextBox2" /> <br />
<asp:Button runat="server" Text="Go" />
<div class="messages">
<asp:ValidationSummary id="summery1" runat="server"/>
</div>
<div>
<asp:Panel ID="Panel1" runat="server" >
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Required Field Validator1 empty" ControlToValidate="TextBox1" Display="None" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="Required Field Validator2 empty" ControlToValidate="TextBox2" Display="None" />
</asp:Panel>
</div>
</form>
HOWEVER....(there's always a catch)... with this method, the Validation Messages themselves are stored in the JavaScript only. Meaning that it won't work if Javascript is disabled. I'm assuming that's not a huge problem since you are working in WebForms (which rely on JS), but I figure it's worth mentioning.
And for the record, accessibility concerns are mostly a crock of horse-crap. I THOUGHT I knew about accessibility until I actually worked with a visually impaired programmer (100% blind). Then, I learned that JS works just fine (assuming they know to look for new content...) and that they just skip around the page from link to link until they find what they are after. And table-based layouts didn't slow them down for 1 second. Boy that was a tough pill to swallow after being SOOO unbearably preachy about CSS for a few years....

chrome automatically set focus on a textbox

I have an aspx form which contains couple of textboxes, dropdownlists and checkboxes on it. I have not set the default focus on any of the control. When I open this in IE it works fine. but when the page opens in chrome it set focus on a textbox which is not the first element of the DOM. and when the page opens in FireFox, it set focus on first textbox in the DOM.
I don't want focus on any of the control, how can I fix this issue.
Can you try document.getElementById('yourElement').blur();?
You could add autofocus = false;
<input type="text" name="second" id="second" "autofocus = false" />
Take look at these links:
http://msdn.microsoft.com/en-us/library/ms178231(v=vs.100).aspx
or
http://msdn.microsoft.com/en-us/library/ms178232(v=vs.100).aspx
Maybe it can help you.
Try setting default focus on from in aspx like this:
<form id="form1" runat="server" defaultfocus="TextBox1" >
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
</div>
</form>
Post your code for more informations.
re: I think that you must have focus on at least one control on page. You can set dummy control like input and set it's opacity in css to 0 and set defaultfocus on it.

IE not catching Enter key for form submission

I have a simple form with one text box that pass data to SQL and I want it to submit when the user hits the enter key.
In Firefox, this works great. The user puts a number hits enter gets back the results.
However in IE 8 and IE 9 this is not working.
<form id="form1" runat="server" accept="cmdclick"
style="background-position: center; background-image: url('BG.gif'); background-repeat: no-repeat;">
<div style="text-align: center">
<br /><br /> <br /><br /><br /> <br /><br /><br />
<asp:TextBox ID="txttrack" runat="server" Height="20px"
Width="175px" Wrap="False"></asp:TextBox>
<asp:Button ID="cmdclick" runat="server"
CommandName="cmdclick" BackColor="White" BorderStyle="None" />
I am not sure what would cause this. I see a lot of people using JavaScript to go around the problem however I do not know how to write JavaScript code.
How can this be done (preferably without JavaScript)?
Set the DefaultButton-Property in Form-Tag:
<form defaultbutton="cmdclick" runat="server">
You can also set the DefaultButton on ASP.NET-Panels. This might not be important in this case but
when you're using MasterPages, because the ID of a Button in a ContentPage is unknown in a MasterPage (Form-Tag is inside the Masterpage)
when you want to have more than one DefaultButton you can set different DefaultButtons to every Panel
If you have recursive form elements (which is against standards compliance) then IE will basically ignore the enter key and not submit the form when it is detected as it doesn't know which form you are trying to submit.

How can I make two textboxes appear as one?

<asp:TextBox id="txtComment" runat="server" Columns="50" MaxLength="50" />
<asp:TextBox id="txtComment2" runat="server" Columns="50" MaxLength="50" />
I have the two textboxes above on a web form. How can I mash them together and make them appear as one text box?
Did you try making a user control or custom control ?
Ideally, create a user control with both your text-boxes and apply the following styling so that they appear together.
First Text box
border-right-width: 0 px
Second Text box
border-left-width: 0 px
You can try putting them right next to each other on the page and styling their borders so they either have no border or the touching sides have no borders.
#txtComment, #txtComment2 {margin:0;padding:0; display-inline; border:none}
Assuming what you actually want is an imperceptible difference between the first and second fields: why not make one textbox, and split it server-side; e.g.
<asp:TextBox id="txtComment" runat="server" Columns="50" MaxLength="50" Visible="false" />
<asp:TextBox id="txtComment2" runat="server" Columns="50" MaxLength="50" Visible="false"/>
<asp:TextBox id="shownTxtComment" runat="server" Columns="100" MaxLength="100"/>
private void splitComment()
{
txtComment.Text = String.Left(shownTxtComment.Text, 49); //first 50 characters
txtComment2.Text = String.Mid(shownTxtComment.Text, 50); //characters 51 thru end
}
call splitComment() in your postback function, and you'll keep the hidden fields up-to-date on every postback.
You might also consider doing the same thing client-side with javascript.
*a cleaner approach would be to remove the txtComment2 web control altogether, set txtComment length to 100, and simply split/handle the substrings on the server, but since it's not altogether clear why you actually want two separate textboxes to look like one textbox, I can't say whether that addresses your need.
I guess I am curious as to why you would want to do this. As Thomas mentioned, it seems to go against usability. Are you looking for something like TextArea

Resources