I have created one simple aspx page using ajax calnder control-- page working fine
but i am creating a user control with ajax calender control and trying to use it with master page its not workng -- after click on button no popup apperring and page got post back,
I am not sure how it works in asp.net, but at MVC to enable calendar, simply add anywhere on the View
<form id="Form1" runat="server" >
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptLocalization="true" EnableScriptGlobalization="true">
</asp:ScriptManager>
</form>
HTH.
Related
I have an .aspx page that dynamically creates multiple user controls, each of which have their own code behind which fires based on several events at the user control level. The problem is, before the events fire in a particular user control, the parent page Load method fires as well. Because each of the controls are added dynamically, this isn't a trivial amount of processing since each control must be re-added.
I'd like to be able to fire UserControl events without forcing an update on the page that hosts it. I've tried putting the entire user control in an UpdatePanel, but postbacks within the user control still force a page load for the parent.
Here's some test code with certain parts omitted and the control added declaratively, instead of programmatically.
.ASPX Parent Page
<%# Page Language="vb" CodeBehind="MyParent.aspx.vb" %>
<%# Register TagPrefix="uc" TagName="Control" Src="MyControl.ascx" %>
<form id="form1" runat="server">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<uc:Control ID="Control1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
.ASCX User Control
<%# Control Language="vb" CodeBehind="MyControl.ascx.vb" %>
<p>Control Added</p>
<asp:Button runat="server" Text="ForcePostBack"/>
This is how the ASP.NET WebForms page life-cycle works. Controls that postback will cause the host (read: parent) page to go through its Page_Load. If you do not like this model, then you should consider ASP.NET MVC or a client-side solution where you can make AJAX calls to acquire data and then do client-side rendering via templating logic.
Can you avoid it by having a Session variable like 'IsFirstLoad', then render the UCs only when IsFirstLoad is null (or true)?
Also, I've found that items rendered in Page_Init dynamically will persist through PostBack, so you wouldn't have to re-render. Don't know if that applies to UCs or not, though.
I am developing my first asp.net website, my requirement is to refresh DropDownListB at SelectedIndexChanged event of DropDownListA, I have set AutoPostBack="True" for DropDownListA. Now the problem is whole web page gets refreshed, its unnecessary for me, is there any other technique that i can use to refresh only that control or only that panel rather than refreshing whole page?
Put the dropdowns inside
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
// Dropdowns
</ContentTemplate>
</asp:UpdatePanel>
and include <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager> at the top
1- You can simply place the dropdown in an UpdatePanel, this will avoid a complete post back.
You can get more details on UpdatePanel here
2- You can use jQuery AJAX to fetch the data in JSON format and bind it to the dropdown list, this approach is more efficient but little complex in comparison to UpdatePanel
You can find so many articles on this if you search this on google , like
[EDIT]
You can find a similar implementation here
I have 3 ASP.Net pages. Each one has a form, a submit button, and a Javascript submit function, which it validates textbox data.
When I convert these 3 pages to Master Page/Content Page, what is the best way to merge three forms and submit functions?
Thanks in advance!
Just because multiple pages have forms doesn't mean the form processing logic should be refactored into a master page. In the codebehind of wherever a form is defined is typically the best place for the form processing logic to go.
If they only differ by the contents of the form, then put everything else into the Master page, and the form alone into each Content Page.
I'd leave the Submit method for each form in it's Content page's code-behind, because these will be independent of each other.
You could have them all link to the same javascript validation file, for neatness, and call different validation methods
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="Validation.js" />
</Scripts>
</asp:ScriptManager>
and have each form's Submit button call its own method, e.g.
<asp:Button ID="btnSave" runat="server" OnClientClick="ValidateFormA" OnClick="Save" Text="Save" />
I would create a web user control to encapsulate the UI and functionality of the submit button, Javascript submit function, and textbox.
Then you could add the control to a master page if you wanted to.
You can put the submit function in the master page and make the content pages define per-page functions or variables that the submit function uses.
For more specific advice, please post more details.
im making a username availability check in ASP.net using ajax updatepanel, but i keep getting the following error
The control with ID 'UserNameUP' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.]
im using the create user wizard, to create a new user but i want to check if the user already exists, i have the following code in the aspx file
<asp:UpdatePanel runat="server" ID="UserNameUP">
<ContentTemplate>
<asp:TextBox ID="UserName" runat="server" Width="200px" AutoPostBack="true" OnTextChanged="Username_Changed"></asp:TextBox></ContentTemplate> </asp:UpdatePanel><br />
but i keep getting that error, can any one help
thanks
Before your update panel, make sure you have a scriptmanager:
<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
Do you have a script manager inside a master page? That can cause the "Only one instance of a ScriptManager can be added to the page" error?
Or, if its DNN, there is one on each "page" by default.
We have an issue on our page whereby the first time a button posts back (we have ASP.NET ajax to enable partial updates) nothing happens, then on every subsequent click, the information is updated as if the previous event fired.
Here's the code for the page. The events are button clicks fired from within the table. Which is rerendered at the backend.
<asp:ScriptManager EnablePartialRendering="true" ID="scrptMgr1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="folderContainer">
<ContentTemplate>
<asp:Table id="FolderTable" CssClass="FolderTable" runat="server" CellSpacing="0"></asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
Any ideas?
Thanks.
Did you try an HTML table, with or without runat="server" ?
Do you add or remove controls inside the table in the postback?
Inspired by Robert's answer:
In which event handler do you build your table? If you build it in Page_Load without checking IsPostBack), then the button's click event has not been handled yet.
You need to build the table in the button click handler.
Your table is probably being populated too late in the page lifecycle. Try creating the table in PreInit.