No event is firing in asp.net - asp.net

In my website No button event is firing.
<asp:Button ID="Button1" Text="Add_Record" runat="server" AutoPostBack="true"
onclick="Button1_Click" />
when I write code in the event handler. It does not call.
On every page of website I am facing this issue.
<div id="eList">
<p>Enter Your Email To Sign Up<br>
For Our E-Newsletter:</p>
<asp:TextBox ID="elist_input" runat="server" Width="169px">
</asp:TextBox>
<br>
<asp:Button class="elist_submit" runat="server" Text="Search" Width="56px"
onclick="Unnamed1_Click" />
<div id="display_menu_2">
<asp:Button ID="Button1" Text="Add_Record" runat="server"
AutoPostBack="true" onclick="Button1_Click" />
Page Directive
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="HomePage.aspx.cs" Inherits="homePage" %>

Your project must have been Web application project and the CodeFile attribute is valid only in Web site project for compiled pages, change it to the CodeBehind like this.
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeBehind="HomePage.aspx.cs" Inherits="homePage" %>

I was not able to call the event handlers. the problem was due to the header.ascx file. In that file I used form and also a form in Master page. As Master page is inhereted to all pages and header is also. due to two form in one page event handlers were not working..

Related

How to keep small part of page uncahced in page out put caching

<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# OutputCache Duration="10" Location="Server" VaryByParam="none" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
</h2>
<p>
To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">
www.asp.net</a>.
</p>
<p>
This is cached date text
<asp:Label ID="lblDate" runat="server"></asp:Label>
</p>
<p>
This is uncached date text
<asp:Label ID="lblDate1" EnableViewState="false" runat="server"></asp:Label>
</p>
<p>
You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
</asp:Content>
In above code I want that only lblDate1 value should change whenever I will refresh the page How can I acheive this.Currently both control values are geting cahced.
Since the page is cached, well - the entire page is cached, and nothing in this call will be retreived again from the server until the cache is invalidated.
You could solve it by doing an ajax call with javascript on document load that gets the updated value from a REST service (or just simulate a service by returning json formatted string from an aspx page), and then update the date value from javascript.

ASP.NET validation missing something?

I usually don't resort to posting questions that seem simple, but this one has me stumped.
I have a text box that is a required field, and when I click submit I want to validate the text box.
Here is my code:
<asp:TextBox ID="txtName" runat="server" CssClass="textboxField" MaxLength="45"></asp:TextBox>
<asp:LinkButton ID="btnAdd" runat="server" CausesValidation="True" >Add +</asp:LinkButton>
<asp:RequiredFieldValidator ID="reqName" ControlToValidate="txtName" ErrorMessage="Name is required." runat="server" />
Everything here looks correct to me syntax wise, but for some reason I am not seeing an error message when the text box is blank and the add button is clicked. Any suggestions?
EDIT: Page directive
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPages/SiteMaster.Master" AutoEventWireup="true" CodeBehind="CodeBehind.aspx.cs" Inherits="Site.Page" %>

problem with html editor

I used Html Editor with firefox on my pc. I switched pcs and I tested my site again.. The HTML editor appears completely messed up across browsers ..It doesnt even look as good as it
is on the original pc i deployed it.
The question is why? And should I use ajax at all instead of jquery?
All the pages markup:
<%# Page Title="" Language="C#" MasterPageFile="~/YourGuruMaster.master" AutoEventWireup="true" CodeFile="PostEdit.aspx.cs" Inherits="PostEdit" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc1" %>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:PlaceHolder ID="PlaceHolder2" runat="server"></asp:PlaceHolder>
<cc1:Editor
ID="Editor1"
Width="850px"
Height="400px"
runat="server"/>
<br />
<asp:Button
id="btnSubmit"
Text="Submit"
Runat="server" onclick="btnSubmit_Click" />
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="Editor1" ErrorMessage="אין להשאיר שדות רקים"
ForeColor="#CC0000"></asp:RequiredFieldValidator>
1.) This is a much deeper problem. You probably need to add more rules to your css stylesheet. If you want the site to look the same across different browsers, you have to look into cross browser support and cross browser compatibility.
2.) The jQuery library has a full suite of AJAX capabilities. There is no need to use self-made js functions to create AJAX calls. Stick with jQuery.

CollapsiblePanelExtender A potentially dangerous Request.Form value was detected from the client

I am encountering this error whenever the button is clicked to collapse/expand the panel.
Error: CollapsiblePanelExtender A potentially dangerous Request.Form value was detected from the client.
Can someone tell me what I did wrong and what is causing this?
<asp:Button ID="Button1" runat="server" Text="Button" />
<ajaxToolkit:CollapsiblePanelExtender
TargetControlID="testPanel"
ID="CollapsiblePanelExtender1"
runat="server"
ExpandControlid="Button1"
CollapseControlID="Button1"
Collapsed="False"
ExpandDirection="Vertical"
AutoCollapse="false"
AutoExpand="false">
</ajaxToolkit:CollapsiblePanelExtender>
<asp:Panel ID="testPanel" runat="server">
stuff here
</asp:Panel>
Put validateRequest="false" in your page directive or web.config file.
Adding Cross-Site Scripting Protection to ASP.NET
for example if you already have:
<%# Page Language="vb" AutoEventWireup="false" Codebehind="MyForm.aspx.vb" Inherits="Proj.MyForm"%>
then this should become:
<%# Page Language="vb" AutoEventWireup="false" Codebehind="MyForm.aspx.vb" Inherits="Proj.MyForm" ValidateRequest="false"%>
Note:
If you are using .NET 4 then you will need to add requestValidationMode="2.0" to the httpRuntime configuration section of the web.config file. For example:
<httpRuntime requestValidationMode="2.0"/>
If you don't already have a httpRuntime section in the web.config file then this goes inside the section.
Thanks

Checkbox inside user control in repeater doesn't fire

I have user control inside a page with single repeater. The problem is when this control is placed inside repeater check box doesn't fire CheckedChanged event. If this would be a dynamically added control I would check whether CheckedCanged event has a handle assigned in Init() but here the event is specified in ascx so I imagine asp.net is responsible for doing all the assignments in right place. I'm lost here :/
By the way. Placing single checkbox inside repeater doesn't fire to. But I can at least use OnItemCommand there
User Control
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="QuoteContainer.ascx.cs" Inherits="EhdSite.Controls.QuoteContainer" %>
<asp:TableRow runat="server" ID="trQuoteRow">
<asp:CheckBox runat="server" ID="cbxConfirm" AutoPostBack="true" OnCheckedChanged="CbxConfirmCheckedChanged" />
</asp:TableRow>
Page
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager2" runat="server" />
<asp:UpdatePanel runat="server" ID="upQuotes" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Repeater runat="server" ID="rptQuotes">
<ItemTemplate>
<ehd:QuoteContainer
runat="server"
ID="qcQuote"
RowCssClass="rowStyle"
HighlightedRowCssClass="selectedRowStyle"
Quote="<%# Container.DataItem %>"
OnQuoteSelectedChanged="QuoteSelectedChanged" />
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
It has to do with the event-chain in ASP.Net, this MSDN page helps to understand it.
The .Net framework resolves the ViewState between the Init- and the Load-event. So if the control is not there after the Init-event, it's ViewState will never be loaded and also it's events will never be fired.
This can get quite tricky at times, especially if one dynamically loaded control should affect the loading of another one...

Resources