My application was working before converting it to an asp.net Master/Content page architecture. There is a custom control that has 3 buttons in one DIV and a chart in another DIV. The custom control is added to the content page many times with a different chart in each. The same event handler services a button, regardless of how many times it appears on the screen.
After converting to a Master/Content page architecture, the event handler no longer receives the onClick event.
The Content Page looks like this...
<%# Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm7.aspx.cs" Inherits="OperationalStats.Forms.WebForm7" %>
<%# Register src="../Classes/UserControls/ChartWidget.ascx" tagname="ChartWidget" tagprefix="uc1" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>
And the user control page looks like this
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="ChartWidget.ascx.cs" Inherits="OperationalStats.Classes.UserControls.ChartWidget" %>
<div id="TestDiv" class="floating-box" runat="server" style="border: medium solid #00FF00; height: 270px; width: 250px">
<div id="MenuDiv" runat="server">
<asp:Button ID="FilterButton" runat="server" Text="Filter" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myModal" OnClick="FilterButton_Click" CommandName="Tests Delivered By Test Center" />
<asp:Button ID="ZoomButton" runat="server" class="btn btn-info btn-sm" Text="Zoom" data-toggle="modal" data-target="#myModal" Width="50px" OnClick="ZoomButton_Click" />
<asp:Button ID="ShowTableButton" runat="server" class="btn btn-info btn-sm" Text="Table" data-toggle="modal" data-target="#myModal" Width="50px" OnClick="TableButton_Click" />
</div>
<div id="ChartDiv" runat="server" style="position: relative; top: 6px; left: 2px; ">
</div>
</div>
The content declaration in the Master page looks like this
<div class="container body-content">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
<hr />
</div>
The following is an example of a button's event handler
namespace MyApp.Classes.UserControls
{
public partial class ChartWidget : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void FilterButton_Click(object sender, EventArgs e)
{
...
}
As I say, the event handler never receives the click event after converting to a Master/Content page architecture.
Thoughts?
Related
I have 2 files :-
Items.aspx with the list of items in a grid view, A button(to open a form for adding new item), and a div with id testing.
code Inside Items.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="Items.aspx.cs" Inherits="FlowerShopAdminPanel.Items" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="header" runat="server">
<div id="dvGrid" class="container">
<!-- This contains the gridview -->
</div>
<div id="testing"></div>
<script>
function openDialog($itemid,$categoryid) {
$('#testing').dialog({
modal: true,
dialogClass: "no-close",
open: function () {
$(this).load('AddItem.aspx?itemid=' + $itemid+'&categoryid='+$categoryid);
$(".ui-dialog-titlebar-close", ui.dialog | ui).hide();
},
height: 500,
width: 500,
title: 'Add Item'
});
}
</script>
<style>
.image {
height: 30vh;
}
.no-close .ui-dialog-titlebar-close {
display: none;
}
</style>
</asp:Content>
This loads a form to add item in a jquery modal. we can upload image to that item using a Button . Above function is on another aspx form in which I am
AddItem.aspx
<div>
<asp:Label runat="server" Text="Category Name"></asp:Label>
<asp:DropDownList runat="server" ID="category_ddl"></asp:DropDownList>
</div>
<div>
<asp:Label runat="server" Text="Item Name"> </asp:Label>
<asp:TextBox runat="server" ID="itemname_txt"></asp:TextBox>
</div>
<div>
<asp:Label runat="server" Text="Description"></asp:Label>
<asp:TextBox runat="server" TextMode="MultiLine" Rows="5" Columns="50" ID="description_txt"></asp:TextBox>
</div>
<div>
<asp:Label runat="server" Text="Main Image"></asp:Label>
<asp:FileUpload runat="server" ID="mainimage_fileupload"/><br />
<asp:Image runat="server" ID="mainimage_img" Visible="false" />
<asp:Button runat="server" ID="fileupload_btn" Text="Upload" OnClick="fileupload_btn_Click" />
<asp:Label runat="server" ID="filename_lbl" Visible="false" ForeColor="Red" Font-Bold="true"></asp:Label>
</div>
<div>
<asp:Label runat="server" Text="Active"> </asp:Label>
<asp:CheckBox runat="server" ID="isActive_chk"/>
</div>
<div>
<asp:Button runat="server" ID="addItem_btn" Text="Add Item" OnClick="addItem_btn_Click"/>
<asp:Button runat="server" ID="cancel_btn" Text="Cancel" OnClick="cancel_btn_Click"/>
</div>
</div>
</form>
Whenever I upload the image it opens up as a normal aspx page. Basically, Whenever the aspx page is refreshed, it opens up as a normal web page. I always want to open it in the jQuery modal.
Please help in resolving this issue.
Thank you
I have a link button that I want to put a hyperlink to that a popup div is called when the button is clicked.
The asp linkbutton is declared as such:
<TD Class="SpreadSheet"<ASP:LinkButtonID="lbtnViewUsers_Edit" Text="Edit" Runat="Server" onclick="#Upload"/></TD>
and the popup to be called is
<div id="Upload" class="overlay" runat="server">
<div class="popup">
<h2>Edit User   </h2>
<a class="close" href="#">×</a>
<div class="content">
<!-- content -->
</div>
</div>
</div>
Is there a way to put a sort of href = "#Upload" to the link button?
What you are looking for is a model pop. Asp.net Ajax tool kit has one, you can learn more about it at here . I created a simple sample of how to use this model pop-up. Bear in mind you first have to add the tool kit to your asp.net project (you can use nuget package manager for this) and register the control to page using
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
use the properties of Model pop extender to show and save your per record data.
<asp:Panel ID="pnlpopup" runat="server" Width="400px">
<asp:Panel ID="headerPanel" runat="server">Header text Here </asp:Panel>
<div class="form-group">
<asp:Label ID="Label1" runat="server" Text="lable 1"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</div>
</asp:Panel>
<div class="form-group">
Other data values here
<asp:LinkButton ID="lbEdit" runat="server">Edit</asp:LinkButton>
</div>
I have a Master page which is inherited in a aspx page named Employee. Below is the relevant code of the aspx page
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Employee.aspx.cs" Inherits="ICA_Nagerbajar.Employee" MasterPageFile="~/Master.Master" %>
<%# Register TagPrefix="e" TagName="Entry" Src="~/EmployeeView/EmployeeEntry.ascx" %>
<%# Register TagPrefix="v" TagName="ViewEdit" Src="~/EmployeeView/EmployeeViewEdit.ascx" %>
<asp:Content ID="ContentBody" ContentPlaceHolderID="MasterBodyPlaceHolder" runat="server">
<div class="tabbable">
<ul class="tabs">
<li>Entry</li>
<li>View/Edit</li>
</ul>
<div class="tabcontent">
<asp:HiddenField ID="TabData" runat="server" />
<div id="tab1" class="tab" style="display:inline-block">
<e:Entry ID="EmpEntry" runat="server" />
</div>
<div id="tab2" class="tab" style="display:inline-block">
<v:ViewEdit ID="EmpViewEdit" runat="server" />
</div>
</div>
</div>
</asp:Content>
Now in one of the ascx page (EmployeeEntry.ascx) Button is working fine. But in the other one(EmployeeViewEdit.ascx) it is not working. Below is the relevant code of EmployeeViewEdit.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="EmployeeViewEdit.ascx.cs" Inherits="ICA_Nagerbajar.EmployeeView.EmployeeViewEdit" %>
<div class="boxed">
<input id="TextBoxUserNameSearch" runat="server" class="textstyle" placeholder="Name" type="text"/>
<asp:Button ID="ButtonSearch" runat="server" Text="Search" class="btnsubmitstyle" OnClick="ButtonSearch_Click"/>
</div>
Server Side Code
#region Search Button Click
protected void ButtonSearch_Click(object sender, EventArgs e)
{
string userName = TextBoxUserNameSearch.Value.Trim();
GetEmployee(userName + "%");
}
#endregion
Few Observations i made
If i replace Button with Link Button its working fine
No Button is working in this ascx though its working in the other ascx
If i comment out the first call to ascx in the parent page then the button is working ie, <e:Entry ID="EmpEntry" runat="server" />
As suggested by #JBKing setting UseSubmitBehaviour property of the Button to "false" solved my problem
<asp:Button ID="ButtonSearch" runat="server" Text="Search" CssClass="btnsubmitstyle" OnClick="ButtonSearch_Click" UseSubmitBehaviour="false"/>
I want to call another ASP Page and pass a parameter (entry.ID).
I have a Master-Page Global.master like this (I will only post a part of code):
<body>
<div id="global" style="height:2000px;">
<form runat="server" id="globalForm">
<div id="body">
<asp:ContentPlaceHolder ID="mainContentPlaceHolder" runat="server">
<div id="mainContent">
</div>
</asp:ContentPlaceHolder>
</div>
</form>
</div>
and a Default.aspx Page which uses the Master-Page:
<asp:Content ID="Content1" ContentPlaceHolderID="mainContentPlaceHolder" runat="Server">
<div id="mainContent">
<% ICollection<Database.Blogentry> entries;
entries = Database.BlogentryDBO.Instance.getAllBlogentries();
foreach (Database.Blogentry entry in entries) { %>
<div class="blogEntryBody">
<div class="blogEntryText">
<%= entry.Content %>
</div>
</div>
<div class="blogEntryFooter">
<span class="blogEntryView">
<%--CALL HERE ANOTHER PAGE WITH A BUTTON AND PASS THE PARAMETER entry.ID-->
</span>
</div>
<%
}
%>
</div>
I already tried it with
<label visible="false" id="LabelEntryId" name="LabelEntryId"><%= entry.ID %></label>
<asp:button ID="Button2" runat="server" class="buttonBlogEntry" text="view more ..." onclick="viewEntireBlog_onclick" CommandArgument='<%# Eval("LabelEntryId")%>' />
but I don't have a CommandEventArgs element in the onClick method but only a EventArgs element so I can't access my CommandArgument?!
And using
<input runat="server" type="text" id="LabelEntryId" value="<%= entry.ID %>" visible="false"/>
and then accessing the input-element in the code-behind isn't possible either, because i have more than one LabelEntryId-Input because of the loop.
Another idea was to do something like this
<asp:button ID="Button1" runat="server" class="buttonBlogEntry" text="view more ..." onclick="<%= Response.Redirect("BlogEntrySortedByCategory.aspx?entryID=" + entry.ID); %>"/>
but I don't know how to do that...
Can you help me please?
have you tried with a standard a tag?
<a href='/someotherpage.aspx?entryid=<%= entry.Id %>'>View more</a>
I have following code snippet in my asp.net webpage.
<div id="descDiv" style="display:none;">
<form>
<asp:TextBox ID="inputDesc" Height="200px" Width="100%" runat="server" TextMode="MultiLine" placeholder="Enter any details you know about this city" required="required"></asp:TextBox>
<input type="button" Class="cancel" value="Cancel" OnClick="hideInput('descDiv');" /><asp:Button ID="Submit_Desc" CssClass="submit" runat="server" Text="Submit" OnClick="Submit_Desc_Click" />
</form>
</div>
When I click the submit button I receive this error:
Invalid postback or callback argument. Event validation is enabled using
<pages enableEventValidation="true"/> in configuration or
<%# Page EnableEventValidation="true" %> in a page.
For security purposes, this feature verifies that arguments to postback or
callback events originate from the server control that originally rendered them.
If the data is valid and expected, use the
ClientScriptManager.RegisterForEventValidation method in order to register the
postback or callback data for validation.
This form is enclosed in another main form which has 'runat' attribute. What should I do to correct this problem?
EDIT:
Here is the shortest code to reproduce the problem:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="descDiv">
<form>
<asp:TextBox ID="inputDesc" Height="200px" Width="100%" runat="server" TextMode="MultiLine" placeholder="Enter any details you know about this city" required="required"></asp:TextBox>
<input type="button" class="cancel" value="Cancel" onclick="hideInput('descDiv');" />
<asp:Button ID="Submit_Desc" CssClass="submit" runat="server" Text="Submit" OnClick="Submit_Desc_Click"/>
</form>
</div>
</div>
<form>
<asp:TextBox ID="TextBox1" Height="200px" Width="100%" runat="server" TextMode="MultiLine" placeholder="Enter any details you know about this city" required="required"></asp:TextBox>
<input type="button" class="cancel" value="Cancel" onclick="hideInput('descDiv');" />
<asp:Button ID="Button1" CssClass="submit" runat="server" Text="Submit" OnClick="Submit_Desc_Click"/>
</form>
</form>
</body>
</html>
You cannot have two forms on your page, remove the form tag just under your div. The one to keep has to be the form runat="server" since it's a .net page.
what you can do is use .net buttons and process whatever they do from code behind
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
</form>
protected void Button1_Click(object sender, EventArgs e)
{
// do something with button 1
}
protected void Button2_Click(object sender, EventArgs e)
{
// do something with button 2
}