Iam trying to use System.Web.UI.WebControls.Calender.
But when I select any date , It post backs automatically. Is there any way to avoid this behavior.
(I dont see the usual property AutoPostback which I set to False to avoid this behavior)
I need the selected date only once user submits the form.
Note- I am using VS2008
I generally avoid avoid the MS calender control because I find it so hard to work with and style. Have you considered something like the jQuery UI date picker, works as you need and far easier to style after too.
http://jqueryui.com/demos/datepicker/#inline
It posts back to set the selected form on the UI. what you can do is use a client side calendar (like jquery ui) or use ajax calendar extender so it will not postback the whole page.
It is possible with MS Calendar. You can customize content of each cell in DayRender event:
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
e.Cell.Text = e.Day.DayNumberText;
}
You can set e.Cell.Text to be div or span with text and javascript onclick event or link. You can put any HTML there.
You cannot disable "Autopostback" of the Standard Calendar control
I think you can use CalendarExtender from AjaxToolkit
<asp:TextBox ID="txtCalendarExtender" runat="server"></asp:TextBox>
<cc3:CalendarExtender ID="Calendar1" PopupButtonID="imgPopup" runat="server" TargetControlID="txtCalendarExtender" Format="dd/MM/yyyy">
</cc3:CalendarExtender>
Remember to add this code at the top of your page:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc3" %>
Remember, there is a forum about this topic where PLBlum says:
The Calendar control included with ASP.NET uses postbacks only. If you added Microsoft ASP.NET AJAX to the page and put the calendar into an UpdatePanel, it can reduce the appearance of postbacks by using callbacks. But it still makes a trip to the server for each click on a date or month.
Related
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 2 aspx files in my project. The first.aspx page has some content on it and when I click on a button, it will launch a frame (second.aspx that only has code to show a calendar) on the same page.
Now once that calendar(second.aspx) loads on first.aspx, I want to click a link on the calendar that will .show() a hidden DIV on the first.aspx page.
How do I access code cross pages? In other words, how can I write some code in second.aspx that will affect first.aspx.
What you're asking for is not really possible. You're probably approaching it the wrong way. What you should do is turn your calendar page into a user control so that it can be used seamlessly in first.aspx.
Here is how to get started with user controls in asp.net:
After you turn it into a user control there are different approaches to getting access to the properties of the user control from your page. Here is one approach using the FindControl method.
Hope that helps.
The easiest solution would be to show and hide your div with jquery. Simple give your div a class like:
<div class="myCalendarDiv" style="display:none" />
And your Button should look like this:
<asp:Button id="myButton" OnClientClick="return ShowCalendar();" runat="server" />
<script type="text/javascript">
function ShowCalendar() {
$(".myCalendarDiv").show();
return false;
}
</script>
Another way would be instead of creating a seprate webpage for the calendar, as proposed you can use a jquery dialog, or make a usercontrol and embedd it on the same page.
(Posted on behalf of the OP).
So since I was dealing with an Iframe, I found out that you can target the parent window which would be first.aspx.
I used "window.parent.MYFUNCTION();" to call my JavaScript function on first.aspx and show the div.
I have a GridView with multiple date columns in it.
For dates, I use textboxes. I would like to use ajaxToolkit:CalendarExtender to make inserting dates easier. But if I place a ajaxToolkit:CalendarExtender in each ItemTemplate, it will make my page much slower. Could you please tell me how I can use one ajaxToolkit:CalendarExtender for all textboxes? I guess, the calendar should appear when the user clicks a textbox. And of course, the calendar should appear somewhere next to the textbox.
Thanks.
I suggest you yo use jQuery plug-in. Visit http://jqueryui.com/demos/datepicker/
this plug-in helps you.
I don't thing there's a way or a easy way to do it. You could think to use another component. Have you known datapicker from jquery ui ? It's nice, free, clean and fast calendar component. Using it, you can apply a css style in your textboxes and filter it by jquery doing a calendar, using datepicker, something like this:
your textboxes inside the gridview:
<asp:TextBox ID="txtDate1" runat="server" CssClass="date" />
<asp:TextBox ID="txtDate2" runat="server" CssClass="date" />
<asp:TextBox ID="txtDate3" runat="server" CssClass="date" />
and in bottom of your webform, you could do a jquery script
<script language='javascript'>
$(function() { // <- page_load in client side with jQuery
// get all inputs that has .date css style and apply datepicker
$("input.date").datepicker();
});
</script>
Read more about jquery ui to know how to setup it on your application (basically, add a javascript file and css file)
Take a look at these links:
http://www.jquery.com
http://jqueryui.com/demos/datepicker/
PS: Sorry for my english!
I want to develop an application in asp.net with C#.
In that application there are one text box and one label.
I want the following functionality:
When I press any key in textbox then I should get this value on .cs page i.e; code behind. And from .cs page I want to add this value to the label.
The problem is that there is no keypress event for an asp textbox and if I take a html text box then I don't get its value on .cs page
How can I come out with this problem?
Because a keypress on a textbox is a client side event but you want to perform server-side processing you will need to use AJAX requests.
You may find the following useful:
AJAX Toolit
Using Jquery to call asp.net page methods
In asp.net the TextBox will have TextChanged event but you will need to enable post back for the button and the event will fire when you tab out of the TextBox.
For the task you want either use javascript or add a button and when this button is do what you want.
I don't think this is a good aproach in web app., In this way you will end with a lot of post-backs.
However, if you still want this functionality. Texbox has TextChanges event, and if you also change the textboxs's AutoPostBack property to true you will get something close, but you will still have to move a currsor.
But it is still a terible solution. Why don't you simply use a button that fires click event instead?
Alternative solution is to use Ajax or javaScript,..
You can simply create a JavaScript-Method for this.
Your Textbox:
<asp:TextBox ID="textBox" runat="server" onkeydown="onFilterTextChanged()">
</asp:TextBox>
Your JavaScript, do a TimeOut to not do this every 0,0001 secs.
function onFilterTextChanged() {
if (timeoutID)
window.clearTimeout(timeoutID);
timeoutID = window.setTimeout(updateFilterText, 600);
}
Send the Values to the CodeBehind, textis your TextBox-Text.
function updateFilterText() {
var text = document.getElementById("<%=textBox.ClientID %>").value;
__doPostBack("<%=textBox.ClientID%>", "CommandArg" + text);
}
You won't need to do as many PostBacks as with the native TextChanged-Event and you can simply use this e.g. for Auto-Extender-Plugins. Pack the TextBox into an UpdatePanel and you're good to go!
Unless of course you do not NEED to go back to the server, in which case just set the labeltext in updateFilterText.
Ugh, this is driving me mad
Im trying to build up a dynamic menu from a bulletedList, most menu items are plain links however the log out button needs to perform some cleanup code.
I cant for the life of me get the BullettedLists onclick event to fire.
The BulletedList is inside a user control (if that makes a difference)
Any ideas?
Or - any ideas for an alternative, better solution?
Code below
BulletedList
<asp:BulletedList OnClick="menu_Click" runat="server" CssClass="MainMenu" ID="loggedInMenu" DisplayMode="HyperLink" />
Adding an element
loggedInMenu.Items.Add(new ListItem("Logout", ""));
Click handler
protected void menu_Click(object sender, BulletedListEventArgs e)
{
user.logout();
Response.Redirect("Default.aspx");
}
You're using the wrong DisplayMode for your BulletedList control. You should use a DisplayMode of LinkButton. When you use DisplayMode.HyperLink:
Users can click links to move to
another page. You must provide a
target URL as the Value property of
individual items.
This is from the MSDN docs for this control. (It's about 3/4 of the way down the page.)
When you use a BulletedList control in HyperLink mode, the value of your ListItem is the URL that you're navigating to. So your static page HTML controls would use ListItem.Value as the href attribute of the <a> tag.
Here's what the HTML markup looks like when you use a DisplayMode of HyperLink (it's a plain old HTML anchor tag w/ a href):
<li>One</li>
But since you want to postback, you should set the DisplayMode of your BulletedList control to LinkButton. When you do that, you'll enable a postback back to your page and your event handler will trap the event. You can then process the click appropriately then. The event argument that's passed in (of type BulletedListEventArgs) will have an Index property, and that will tell you what item in your list was clicked.
Here's the updated .aspx code that I used:
<asp:BulletedList ID="bullet" runat="server" DisplayMode="LinkButton"
onclick="bullet_Click">
<asp:ListItem Text="One" Value="1">One</asp:ListItem>
</asp:BulletedList>
Everything else is the same except the DisplayMode, which is set to LinkButton. When I use that, then my bullet_Click event handler is fired when I click a list item.
I hope this helps!!