I have a C# ASP.NET application that has a Main Page with 3 ASCX controls. Each control has a text box and a link button associated with it.
Since they are all part of the same form, they can all create a postback. In the click event for each ascx file (on their linkbutton) I modify a public bool iHaveBeenClicked to True.
In the main page, on Page_Load I modify a label with value for each ascx's iHaveBeenClicked.
It always returns False even though the post back occurs and I click on one of the buttons.
here is the code
Thanks for looking into this
I know its got to be something really foolish, I just cant see it right now.
wbochar
Since they are all part of the same form, they can all create a postback. In the click event for each ascx file (on their linkbutton) I modify a public bool iHaveBeenClicked to True.
In the main page, on Page_Load I modify a label with value for each ascx's iHaveBeenClicked.
It always returns False even though the post back occurs and I click on one of the buttons.
here is the code
Code:
--------------------- ASCX File
<%@ Control Language="C#" AutoEventWireup="true" EnableViewState="true" CodeFile="SearchAll.ascx.cs" Inherits="SearchAll" %>
<div style="border:solid 1px #000000; width: auto; height: 61px;">
<table width=100%>
<tr>
<td valign=middle align=center>
<asp:TextBox ID="SearchAllTextBox" EnableViewState=true runat="server" Width=94% Font-Size="18pt" Height="22px"></asp:TextBox>
</td>
</tr>
<tr> <td valign=middle align=center>
<asp:LinkButton ID="QuickSearchLinkButton" runat="server" CssClass="QuickSearchButton"
Font-Underline="False" BackColor="Silver" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" Font-Names="Arial" Font-Size="10pt" ForeColor="Black" Height="98%" Width="94%" OnClick="QuickSearchLinkButton_Click" CommandName="QuickSearchLinkButton_Click">Quick Search</asp:LinkButton></td>
</tr>
</table>
</div>
--------------------- ASCX Code behind
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class SearchAll : System.Web.UI.UserControl
{
private bool _QuickSearchButtonPressed = false;
public bool QuickSearchButtonPressed
{
get { return _QuickSearchButtonPressed; }
set { _QuickSearchButtonPressed = value; }
}
public string QuickSearchText
{
get { return SearchAllTextBox.Text; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
public void QuickSearchLinkButton_Click(object sender, EventArgs e)
{
_QuickSearchButtonPressed = true;
}
public SearchAll()
{
//
// TODO: Add constructor logic here
//
//this.QuickSearchButtonPressed = false;
}
}
---------------- postbackTest.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PostBackTest.aspx.cs" Inherits="PostBackTest" %>
<%@ Register Src="SearchAll.ascx" TagName="SearchAll" TagPrefix="x" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<x:SearchAll ID="SearchAll1" runat="server" EnableViewState="true" />
<br />
<x:SearchAll ID="SearchAll2" runat="server" EnableViewState="true" />
<br />
<x:SearchAll ID="SearchAll3" runat="server" />
<br />
<asp:Label ID="Label1" runat="server" Text="Label" Width="80%"></asp:Label>
</form>
</body>
</html>
--------------- postbacktest.apsx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class PostBackTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text ="1:" + SearchAll1.QuickSearchButtonPressed + " 2:" + SearchAll2.QuickSearchButtonPressed + " 3:" + SearchAll3.QuickSearchButtonPressed;
}
}
-------------------------------------------------
Thanks for looking into this
I know its got to be something really foolish, I just cant see it right now.
wbochar