Can I use my beloved Calendar Extender in MVC? - c#

I love the calendar extender, but I am unable to use it in my MVC app. How do I connect the calendar extender to a textbox in MVC... or add the extender at all for that matter?
Old Way...
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
...
<asp:TextBox ID="txtDate1" runat="server" ValidationGroup="DateCheck">
</asp:TextBox>
...
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
...
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtDate1">
</cc1:CalendarExtender>

Yes you can - if you use the Microsoft Ajax libraries. Link here. Calandar code here.
If you go to Stephen Walthers bolg - here I'm sure there's an example of using the server side controls if memory serves me correctly.

Why not use the JQuery UI datepicker?
See JQuery UI DatePicker

You have to setup your view like a web form, or use a web form within the MVC application, as it requires a form with runat server and a scriptmanager on the view page.

I found the solution. A pretty helpful step by step link that gave me EXACTLY what I want...CodeSprouts.com helped me out alot. Thanks for the directions!!!

Related

Is it possible to have client-side only validation on asp.net controls?

First, I know I can use Javascript, but let me explain.
My goal is to be able to use any of the validators:
Required
Regex
Compare
etc.
And benefit only from their client-side validation. I'm sub-classing inherited controls and preventing the name attribute from being rendered to the client. The reason is for sensitive data that I don't want going back to the server. Removing the name attribute prevents the value from being sent with the control.
Take required field for example, it always fails validation on the server because the value isn't sent. I could use a custom validator but want to leverage all the pre-built features of all the validate types.
Hoping someone had a creative idea, thought, or if I'm blind to the obvious, or if it's just straight up impossible.
Resetting the IsValid property of the validator in the overridden Validate function of the page seems to work:
public override void Validate()
{
base.Validate();
rfvNotEmpty.IsValid = true;
}
I know this question is pretty only but if someone need it, I've got a simple solution.
You simply created your client-side validator to be Enabled="false" and in the PreRender event you enabled It, The server-side validation appear before the PreRender so it will be ignore because it's disabled, but the prerender will generate client-side code and the validator will be enabled and working.
You can try to use ASP.Net Ajax Control Toolkit, it is an open source library for web development.
If you want to use standard Asp.Net Control, you can use the validation controller there is compare, custom, range, regex, and required field validator.
regards
If i understand you question correctly you want your server side validation control to work client side , then you need to add reference of latest jquery file on your page as showing in example.
Server side control will validated client side and form will not be posted to server side until validated client side.
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="ValidationTest.aspx.vb" Inherits=".ValidationTest" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<asp:Panel runat="server">
<asp:TextBox runat="server" ID="txtName" CssClass="form-control" />
<asp:RequiredFieldValidator
ID="rvtxtName"
InitialValue=""
runat="server"
ControlToValidate="txtName"
ForeColor="Red"
ErrorMessage="*Field Required!"
Display="Dynamic"
ValidationGroup="add">
</asp:RequiredFieldValidator>
<asp:Button runat="server" ID="btnSubmit" Text="Save" ValidationGroup="add" />
</asp:Panel>
</form>
</body>

Error: Extender controls may not be registered before PreRender

I am trying to add Ajax Controls to my *.aspx pages.
I just added
<asp:CalendarExtender TargetControlID="UserName" runat="server">
</asp:CalendarExtender>
And getting the error. Any solution?
Please don't tell me to read the similar questions on stackoverflow.com. None worked for me.
As discussed in the chat, you should never put the :
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server">
</asp:ToolkitScriptManager>
Inside a LayoutTemplate, as in the Login control for you case, see http://forums.asp.net/post/5101565.aspx.

In what language is this page written

my question is the following
I need to change a menu in this page, but how do I recognize how this page was written.
Normally, I do stuff in php, but this is new to me.
I can see the words asp and c#, but it is not developed as a "dot net thing", is it?
..otherwise I would need visual studio, I guess?
the homepage code
<%# page language="C#" autoeventwireup="true" inherits="_Default, App_Web_npdtwtc3" masterpagefile="~/Site.Master" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.2.74.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('.slideshow').cycle({
fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
});
});
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<p align="left">
<br />
<br />
<br />
<br />
<font size="9">Multi Mind</font> <br /><br />
<IMG SRC="images/contactgegevens3.png" ALT="" ALIGN=RIGHT><br />
Tax Recruitment is de specialist op het gebied van arbeidsbemiddeling voor fiscalisten.<br />
Het richt zich
thanks, Richard
It appears to be a ASP.NET Web Forms page (ie. .aspx).
So mostly mark up, either run on the server (elements with runat="server") or client (other HTML elements) but there is some JavaScript using JQuery.
For an introduction to ASP.NET Web Forms try here (this is .NET v4, but has links to the pages for earlier versions): http://msdn.microsoft.com/en-gb/library/ms178125.aspx
It's an ASP.NET Web Site or Application (someone help explain the difference in this context) and that particular file is an ASP.NET Web Form. There's generally no need for Visual Web Developer, you could use any text editor really - but it sure makes it easier.
Note that your example uses master pages so you're only looking at the unique content for that particular page - the menu you're after is likely the same across different pages (?) and hence specified in a master file (the name and path to it is defined on the first line). Perhaps looking at that file would make things clearer.
This is ASP.NET with C# as the code-behind. Also a little bit of javascript in there. You will most likely need Visual Studio to edit this easily. You can get visual studio express for free from here:
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express
Good luck with your work.
As stuartmclark mentioned, this is an ASP.net page with C# as code behind language. To explain this,
language="C#" tells you that the code behind is C#. If you are now aware of code behind concept, you can think of this as server side script.
asp: anything starting with asp: are the ASP.net controls. This tells that this is an asp.net page.
And yes, to work on this you need either Visual Studio or Visual Web Developer. You can downlaod Visual Web Developer from here. It's free (as in free beer) from MicroSoft.
Hope this will clarify your doubt.

What is the easiest (correct) way in ASP.NET MVC 2 to make a button-click display text?

I need to make a quick demo showing how to do interactivity on an ASP.NET MVC page.
I opened an ASP.NET MVC project in Visual Studio 2010, put the view in design mode, dragged in a button, double-clicked on it and looked at the view again. I was expecting to see some ingenious JQuery code generated but instead an <asp:Button> and a <script runat="server"> block was created, which seems to be a mixing of classic ASP.NET and ASP.NET MVC metaphors. I don't think that is the recommended way to build interactivity in MVC, right?
So what is the easiest, most standard-MVC approach for me to (1) create a button, (2) when the button is clicked, change some text in my view?
is it really best practice in MVC to use the runat-server block?
are there some easy wizards which generate JQuery interactivity so that I can do this in a best-practice MVC way?
or do I need to implement the JQuery myself as I would on a plain HTML page without ASP.NET MVC?
View:
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form id="form1" runat="server">
<h2><%: ViewData["Message"] %></h2>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</p>
</form>
</asp:Content>
You should not use asp.net ajax controls in asp.net MVC.
If you want to create a button just write some old-fashioned html like:
<input type="button">Button</input>
then if you need this button to make some action, just write new action instead of code behind method like and call it like:
<input type="button" onclick="javascript:window.location = 'http://mypage.com/mycontroller/buttonaction' />
or even better create a link instead of button by using mvc builded-in html helpers:
<%= Html.ActionLink("Do something" ,"ButtonAction") %>
Faster you catch it better for you. You need to resign from asp.net ajax habit. There is no postback or code behind and it's removed with a reason. MVC is controlled by executed actions which means that you are steering the application by calling specified links. By using pure html you've got lot more control on your output code and flow of actions in your application.
Remember that MVC is not a new ASP.NET AJAX and those two will goes together, so if this style of writing we apps does not suits you then you do not need to use it. It's just the metter of choice which technology is better for you and your projects.
Also to learn more about mvc visit asp.net mvc webpage. I specially recomend you to see some videos like this one. It will definitely help you to better understand what mvc is and what are it's advantages and disadvantages.

Textbox1.Focus(); does not work; as does not Page.SetFocus(Textbox1); why?

as stated both of these do not work (from Page_Load):
Textbox1.Focus();
or
Page.SetFocus(Textbox1);
any idea why?
this is the control itself:
<asp:TextBox ID="Textbox1" ClientIDMode="Static" CssClass="Textbox1"
runat="server" MaxLength="80"></asp:TextBox>
it is located on a page, two master pages deep. the form tag is on the second master page, so that is why the focus is not being set there.
not working in: ie, firefox, chrome and safari (all latest versions).
help!
thnx
edit: need any more info? i'll do / post anything just tell me what to do to help you help me, i tried EVERYTHING. even google is out of results and is showing my this question.
ok, here is what the ACTUAL problem seems to be.
<asp:Content ID="PlaceHolder1" ContentPlaceHolderID="PlaceHolder1"
runat="server">
i have no idea how those ID's (ID="PlaceHolder1") got there, but they seem to be the problem.
i figured it out by remaking the project from scratch and seeing if the focus method works in there, then (among other things, so I could post here) i found out this difference.
this works:
<asp:Content ContentPlaceHolderID="PlaceHolder1" runat="server">
hope this helps someone, sometime...
Have you tried this?
<form id="Form1" defaultfocus="Textbox1" runat="server">
Or since you mentioned a page in within a MasterPage so it will be in a ContentPlaceholder:
ContentPlaceHolder cp = (ContentPlaceHolder) Master.FindControl("ContentPlaceHolder1");
cp.FindControl("Textbox1").Focus();
Make sure you reference your Master in your aspx:
<%# MasterType VirtualPath="~/MyMaster.master" %>
you can write the js code control the textbox in the client event window.onload=.....
if your page use the master page , you should find the the textbox firstly ,so then set the textbox focus. and you also should attention the events sequence of the page and master

Categories

Resources