I have a checkbox, a button, and a CKEditor control (v3.6.1) that I've added to an existing asp.net webform page. Clicking the button saves the status of the checkbox and the contents of the CKEditor to the database and displays a saved successfully message. If the user modifies either one, the message should disappear. Well, the OnTextChanged event isn't firing on the CKEditor so that the label displaying the message can be hidden. I have tried doing this with javascript using the onkeypress event. I wrapped the CKEditor in a tag and put the onkeypress="..." on that with no luck. I even used jQuery to attach a function to the OnTextChanged (tried OnChanged too) event on document ready with no luck. This is driving me crazy as to why this simple thing won't work and it's the only thing holding me up from completing my project (at least going to the next phase). Can someone please help me with this as to why this isn't working. Code pertinent to this issue is pasted below:
.aspx
<tr>
<td>
<CKEditor:CKEditorControl runat="server" ID="txtClientProtocols" name="txtClientProtocols" Width="1000" Height="370" EnterMode="P"
ResizeEnabled="false" AutoPostBack="True" OnTextChanged="txtClientProtocols_TextChanged"></CKEditor:CKEditorControl>
</td>
</tr>
.aspx.cs
protected void txtClientProtocols_TextChanged(object sender, EventArgs e)
{
lblSuccess.Style["visibility"] = "hidden";
}
I did some research but haven't found anything that stood out as a solution. Thanks in advance for any help.
Following the recent CKEditor 3.6.2 release we would like to announce
the availability of our integrated version for ASP.NET. The ASP.NET
control was updated to the latest CKEditor version and contains all
the bug fixes and new features introduced in CKEditor 3.6.2, including
initial support for iOS5 and some API additions.
Apart from the changes included in the editor, some new features are
offered exclusively for the ASP.NET control: the OnTextChanged event
is now fired and the AutoPostBack property is available.
The scripts registration has been moved from OnLoad to OnPreRender, so
setting configuration in the code should now be always working. Issues
with Ajax postback should be also gone.
What's new ASP.NET
You should upgrade your version.
I have a very long form that has to be filled out. I have maintainScrollPositionOnPostBack enabled as I have multiple controls that hide/show based on user input.
Since the form is long I'd like for the page to focus and scroll to the first control that caused validation to fail and I have the focus on validation fail option enabled. However, it seems that maintainScrollPositionOnPostBack overrides this (the control does focus but doesn't scroll up to it).
Any ideas for workarounds for this? Everything I've tried so far hasn't worked. It is an asp.net webforms project.
This is a good question and really tricky to get working. But I managed to get one version that you can try and maybe build on.
The MaintainScrollPositionOnPostback="true" -setting sets a series of javascript-events on form submit and window load and these do as you say, "overwrite" the focus set by the validator.
So what I did was add a common css-class to all validators like so:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" CssClass="error" ErrorMessage="RequiredFieldValidator" SetFocusOnError="true"
EnableClientScript="false" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
And then I added another eventlistener to window.load (note we need to leave also the one that Asp.Net has added so we cannot do windows.load = function...):
<script>
window.addEventListener("load", function () {
var el = document.getElementsByClassName("error");
if (el.length > 0) {
window.location.hash = "#" + el[0].id;
}
});
</script>
Here you might benefit from jQuery use to be able to support more browsers but addEventListener is pretty well supported.
The script searches for the errormessage and focus on that by it's id with anchor. Javascript has focus-method but it's for form elements so that's why this workaround.
Hope this helps!
Basically i've got a settings page, and when you check the checkbox, it should hide certain topics on another page...
How would i go about checking whether the checkbox is checked?
Just need ideas on how to approach it.
(ASP and C#)
Thanks,
Becki
asp.net c# is checkbox checked?
Specify event for Button Click
<asp:Button ID="PublishButton" runat="server" Text="Save" onclick="PublishButton_Click" />
Just you can store the return value ie true or false in a session variable. So that every page can know that whethere the particular check box is checked or not. With this you can automate your code. I haven't tried it but it may work i guess. ie.
`if(checkbox.checked)
session["variablename"]=true;// u have to decide
else
{
// false statement
}
`
Hence this variable session["variablename"] can be accessible in that particular user session about 20mins.
You can check your setting by ajax call in time periods.
To do this :
Settings page changes value from 0 to 1 in your database.
Your pages should have jQuery ajax calls to get the latest value of your setting and apply it.
I hope it help.
I hope I can explain this well without having to post scads of source.
I have a page in an online store that lets the user pick a date for a tour. That page has a ConLib which contains a couple of panels. The first is:
<asp:Panel ID="pnl_Grid" runat="server">
<cb:SortedGridView ID="VariantGrid" runat="server"
AutoGenerateColumns="False" Width="100%"
SkinID="PagedList" DataKeyNames="OptionList">
<Columns>
</Columns>
</cb:SortedGridView>
</asp:Panel>
and then another asp:Panel with other stuff - calendar, buttons, etc. The SortedGridView is supplied by our shopping cart provider and is basically a regular asp:Grid.
When the user says they want 3 tickets I do a
pnl_Grid.Enabled="false"
to keep them from changing it after picking a date/time. At various points they can click a reset button that will do many things but one task is to set the value to zero in the gridrow text boxes and enable the Grid since they reset the process and want to pick new things.
I have stepped through the code with breakpoints in place and it seems that the problem I am having is that my reset button click event handler fires after the Grid is rendered with the disabled status in the Page Render stage of life. If that is true then setting the Grid in code behind will never show the enabled grid on the page without a refresh since it's already rendered. If I refresh the page manually it does indeed show as enabled so I think I'm on the right problem.
My question is twofold, if there is enough info here to answer it:
1. Is it likely that what I think I am seeing is true - the page renders the control disabled and then the button handler tries to enable it but it's too late at that point since the control is already rendered?
2. How can I work around this? I would prefer to avoid JQuery if at all possible... it has some unintended side effects with the way our original store software is written.
Further info:
I have a status flag _EventSelected which tells if the calendar event has been selected. On the reset button click I set that to false and on PreRender I check that to see if it is false and enable the Grid. Again, the status doesn't change until the Reset Button Click event handler and that is after the PreRender.
Thanks for your input! I swear, some days ASP.NET makes perfect sense to me and other days it is clear as mud.
I found a working solution. To force the page to refresh after the button enables the Grid, which is not displayed without the refresh, I added this to the btn_Reset_Click handler, found by searching for "cause page reload":
Page.Response.Redirect(Page.Request.Url.ToString(), false);
It's not a bad solution since I'm in a reset / start-over state anyway. Thanks for taking time to read my question! Hopefully this will help someone else some day.
The __doPostBack is not working in firefox 3 (have not checked 2). Everything is working great in IE 6&7 and it even works in Chrome??
It's a simple asp:LinkButton with an OnClick event
<asp:LinkButton ID="DeleteAllPicturesLinkButton" Enabled="False" OnClientClick="javascript:return confirm('Are you sure you want to delete all pictures? \n This action cannot be undone.');" OnClick="DeletePictureLinkButton_Click" CommandName="DeleteAll" CssClass="button" runat="server">
The javascript confirm is firing so I know the javascript is working, it's specirically the __doPostBack event. There is a lot more going on on the page, just didn't know if it's work it to post the entire page.
I enable the control on the page load event.
Any ideas?
I hope this is the correct way to do this, but I found the answer. I figured I'd put it up here rather then in a stackoverflow "answer"
Seems it had something to do with nesting ajax toolkit UpdatePanel. When I removed the top level panel it was fixed.
Hope this helps if anyone else has the same problem. I still don't know what specifically was causing the problem, but that was the solution for me.
Check your User Agent string. This same thing happened to me one time and I realized it was because I was testing out some pages as "googlebot". The JavaScript that is generated depends on knowing what the user agent is.
From http://support.mozilla.com/tiki-view_forum_thread.php?locale=tr&comments_parentId=160492&forumId=1:
To reset your user agent string type about:config into the location bar and press enter. This brings up a list of preferences. Enter general.useragent into the filter box, this should show a few preferences (probably 4 of them). If any have the status user set, right-click on the preference and choose Reset
I had this same problem (__doPostBack not working) in Firefox- caused a solid hour of wasted time. The problem turned out to be the HTML. If you use HTML like this:
<input type="button" id="yourButton" onclick="doSomethingThenPostBack();" value="Post" />
Where "doSomethingThenPostBack" is just a JavaScript method that calls __doPostBack, the form will not post in Firefox. It will PostBack in IE and Chrome. To solve the problem, make sure your HTML is:
<input type="submit" id="yourButton" ...
The key is the type attribute. It must be "submit" in Firefox for __doPostBack to work. Other browsers don't seem to care. Hope this helps anyone else who hits this problem.
this might seem elemental, but did you verify that your firefox settings aren't set to interfere with the postback? Sometimes I encounter similar problems due to a odd browser configuration I had from a debugging session.
Is it because you are doing return confirm? seems like the return statement should prevent the rest of the code from firing. i would think an if statement would work
if (!confirm(...)) { return false; } _doPostBack(...);
Can you post all the js code in the OnClick of the link?
EDIT: aha, forgot that link button emits code like this
<a href="javascript:__doPostBack()" onclick="return confirm()" />
Are you handling the PageLoad event? If so, try the following
if (!isPostBack)
{
//do something
}
else if (Request.Form["__EVENTTARGET"].ToLower().IndexOf("myevent") >= 0)
{
//call appropriate function.
}
Check if you are getting a call this way, if so then maybe the event is not wired and nedes to be explicitly called.
what do you expect from "Enabled = 'false'" ?
I have had problems with firebug on some web forms, something to do with the network analyser can screw with postbacks.
With or without the OnClientClick event it still doesn't work.
The _doPostBack event is the auto generated javascript that .NET produces.
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
*The &95; are underscores, seems to be a problem with the stackoverflow code block format.
Now that i think about it, as noted in my last edit, you want to drop the javascript: in the on client click property. It's not needed, because the onclick event is javascript as it is. try that, see if that works.
Seems it had something to do with nesting ajax toolkit UpdatePanel. When I removed the top level panel it was fixed.
Hope this helps if anyone else has the same problem.
I had this exact same issue in a web app I was working on, and I tried solving it for hours.
Eventually, I did a NEW webform, dropped a linkbutton in it, and it worked perfectly!
I then noticed the following issue:
...
I switch the order to the following, and it immediately was fixed:
...
IE had no issue either way (that I noticed anyway).
I had a similar issue. It turned out that Akamai was modifying the user-agent string because an setting was being applied that was not needed.
This meant that some .NET controls did not render __doPostBack code properly. This issue has been blogged here.
#Terrapin: you got this exactly right (for me, anyways).
I was running User Agent Switcher and had inadvertently left the Googlebot 2.1 agent selected.
In Reporting Services 2008 it was causing the iframes that reports are actually rendered in to be about 300x200 px, and in Reporting Services 2008 R2 is was throwing "__doPostBack undefined" errors in the Error Console.
Switching back to the Default User Agent fixed all my issues.
I had the same problem with Firefox. Instead of using __doPostBack() could you use the jQuery .trigger() method to trigger a click action on an element that has your postback event registered as the click action?
For example, if you had this element in your aspx page:
<asp:Button runat="server" ID="btnMyPostback" OnClick="btnMyPostback_Click" CssClass="hide" ToolTip="Click here to submit this transaction." />
And your postback event in your controller:
protected void btnMyPostback_Click(object sender, EventArgs e)
{
//do my postback stuff
}
You could do the postback by calling:
$("#btnMyPostback").trigger("click");
This will cause the Page_Load event to fire if you need to do something on Page_Load.