How to disable autocomplete when using master pages - asp.net

We are migrating a existing asp.net application without master pages to a new one with master pages.
Old Code:
<form id="Form1" method="post" runat="server" autocomplete="off">
When using master pages how will we put autocomplete="off" in ContentPlaceHolder?
can we use
<asp:Content ID="Content1" ContentPlaceHolderID="ContentArea" runat="server" autocomplete="false">

If you want to disable it globally you should use jQuery:
$(document).ready(function () { $("input").attr("autocomplete", "off"); });

Add autocomplete="off" to Site.Master's Form tag.
Like this...
<form id="MasterForm" runat="server" autocomplete="off">

Related

ASP.NET DatePicker (VB)

I don't see any date picker in ASP.NET controls.
Anyone knows how to add it in my my webpage.
I am using VB as my programming language.
Result
I would like to thank everyone who posted the solutions, code and links which helped me to achieve this thread goal. Based on all of the source the below code is the one which works nicely.
Content1
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.min.js"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
//initialise the datepicker with the date format specified
$(".datepicker").datepicker();
});
</script>
And in
Content2
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:TextBox runat="server" ID="txt_MyDate" CssClass="datepicker" MaxLength="10" />
Add this inside your [head] Tag.
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
and use this jquery function in aspx page inside [script] tag
$(function () {
$("#datepicker").datepicker();
$("#datepicker").change(function () {
$('#btnRefresh').click();
});
and add one textbox for display selected date. and button for getting the date in sever side. like this code
<input type="text" id="datepicker" runat="server" clientidmode="Static" />
<asp:Button ID="btnRefresh" runat="server" onclick="btnRefresh_Click" ClientIDMode="Static"
Text="Refresh" AutoPostback="true" style="display:none;"/>
use this onclick event to do want you want..
You're right, there isn't anything built-in.
Personally I would recommend the jQueryUI datepicker - it's reliable and flexible, and it's javascript based, so it doesn't matter what your server-side language is.
See https://jqueryui.com/datepicker/
Once you've added the required references to jQuery and jQueryUI, in your aspx page, add a script section like this:
<script type="text/javascript" language="javascript">
$(function () {
//initialise the datepicker with the date format specified
$(".datepicker").datepicker();
});
</script>
and then add the "datepicker" class to any textbox controls on the page where you want to use the datepicker:
<asp:TextBox runat="server" ID="txt_MyDate" CssClass="datepicker" MaxLength="10" />
P.S. I can also recommend most of the rest of the jQueryUI package, there are some useful items in there which can speed up your development time and make your apps look nicer and be more usable.
You can implement a datepicker on your page with the help of the Calendar control, using javascript on your page. Try this links for simple methods to do it:
http://www.vbknowledgebase.com/?Id=150&Desc=ASP.Net-DatePicker-using-Calendar-Control
http://www.codedigest.com/Articles/ASPNET/247_DatePicker_Control_in_ASPNet.aspx
http://www.aspsnippets.com/Articles/DateTimePicker-control-for-ASPNet-TextBox-Example.aspx

why it says there are not my text boxes

i wrote below code . but i do not know why i get error. but every thing seems ok.
it says there are not my text boxes in context. but there are .
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<form id="form1" runat="server">
<asp:TextBox ID="address" runat="server"/>
<div class="form1">
<label for="fname">
<span>name:</span>
<asp:TextBox ID="fname" runat="server"/>
</label>
<label for="lname">
<span>lname: </span>
<asp:TextBox ID="lname" name="lname" runat="server" />
</label>
.
.
.
</div>
protected void send2_Click(object sender, EventArgs e)
{
tbl_register tbl = new tbl_register();
tbl.firstname = fname.Text; // The name 'fname' does not exist in the current context
tbl.lastname = lname.Text; // The name 'lname'does not exist in the current context
tbl.address = address1.Text; //..
tbl.phone = phone.Text; //..
tbl.email = email3.Text; //..
db.tbl_registers.InsertOnSubmit(tbl);
db.SubmitChanges();
}
The textboxes as coded are children of the label. I do not code my lables in that way. In order to use controls that are child controls you must use Control.FindControl, in this case fname.FindControl("fname"). I would not name controls the same as other controls. You can also close the label tag such that it does not enclose those controls, and then the control can be referenced via the name.
the line
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
suggests that this is a webform that uses a MasterPage.
inside the content place holder you have a form declaration that runs at server:
<form id="form1" runat="server">
however, on your MasterPage.master you already have a form that runs at server that wraps the content placeholder.
asp.net does not allow 2 nested forms to both run at server.

Not retrieving UserControl from a placeholder control

I have a datagrid with dropdown template under .ascx page. I load it on placeholder control on my .aspx page by using:
Control c = Page.LoadControl("~/CreateChecklist/GridWithMultiDropdown.ascx");
PlaceHolder1.Controls.Add(c);
Now i am trying to read datagrid template white in under placeholder from .aspx page but its show me the "ctl00$palceholder$drodownlist" not taking as a control.
Please help me how can i retrieve this datagrid data under placeholder.
Discard your server side code, go to aspx page then register your control and then place ur control tag inside placeholder and bang, it will work :)
Solution:
<%# Register Src="~/WebUserControl.ascx" TagName="myControl" TagPrefix="myControl" %>
<html>
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder ID="phControl" runat="server">
<myControl:myControl ID="ctrlControl" runat="server" />
</asp:PlaceHolder>
</div>
</form>
</body>
</html>
Regards
Ali Muhammad

fileupload control not working in the update panel

HI,
fileupload control is inside a grid, When Ajax is not used its s working correctly, so as wen i use a Update panel, am getting a error in uploading my file to thr database, plz help me in this.
Please advice me
Dhanraj.S
You can set Post Back trigger on Submit button. after that you can get image at server side.
for ex.
<Triggers>
<ajax:PostBackTrigger ControlID="btnSubmit" />
</Triggers>
Thats because the UpdatePanel does not retain the file inside the asp:FileUpload
Workaround is to set a PostBackTrigger on the button that updates the UpdatePanel
Suppose there is a Button ( lets say UploadFileButton ) that Updates the UpdatePanel. Alter your Panel like this
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:FileUpload ID="TestFileUpload" runat="server" />
<br />
<asp:Button ID="UploadFileButton" runat="server" Text="Upload File"/>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="UploadFileButton" />
</Triggers>
</asp:UpdatePanel>
Have you tried to use the new AsyncFileUpload Control from AjaxControlToolkit 3.5? Here is a step by step guide.
Probably not what you are looking for but why not use jQuery to upload the file? You can use jQuery Form Plugin to do it.
This is the script:
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/jquery.form.js"></script>
<script type="text/javascript">
$("#myForm").ajaxForm({
success: function (response) {
$('#updateDiv').append(response);
}
});
</script>
And this is the HTML:
<form id="myForm" action="http://localhost/Default.aspx" method="post"
enctype="multipart/form-data">
<div id="updateDiv" runat="server">
</div>
<div>
<input type="file" id="filePhoto" name="filePhoto" value="" />
<input type="submit" value="Upload Photo" />
</div>
</form>
Of course you will have to handle the form submission in your code-behind and send back the appropriate response.

How can I enable live preview for FCKeditor in an ASP.Net site?

Over in this question, Scott writes that it is possible to get the current HTML for what's written in the FCKeditor by using FCKeditorAPI.__Instances['instanceNameHere'].GetHTML();
Could someone provide step-by-step instructions on how to accomplish this in an ASP.NET page? All I currently have so far in the .aspx file is this:
<%# Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<%# Page Title="" Language="C#" ... %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h2>Create a new piece</h2>
<form id="form1" runat="server">
<FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server">
</FCKeditorV2:FCKeditor>
<input id="Submit1" type="submit" value="Submit" runat="server" />
</form>
</asp:Content>
In javascript
Well you can do this here:
<script type="text/javascript">
var oEditor = FCKeditorAPI.GetInstance(’IDFromFCKEditor’);
oEditor.Events.AttachEvent( 'OnSelectionChange', function() {
document.getElementById("PreviewDiv").innerHTML = oEditor.GetHTML(true);
}) ;
</script>
Source http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/JavaScript_API

Resources