how to display database information (evals? labels? literals?) - c#

I have the following asp.net page
<form id="form1" runat="server">
<asp:Button id="display_button" runat="server" Text="Display" OnClick="Button1_Click" />
<asp:Button id="edit_button" runat="server" Text="Edit" OnClick="Button2_Click" />
<asp:Button id="save_button" runat="server" Text="Save" OnClick="Button3_Click" Visible="false" />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<asp:MultiView id="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View id="View1" runat="server">
<asp:FormView id="view_program" runat="server">
<ItemTemplate>
<tr>
<td class="add_border_bold" nowrap">Status</td>
<td width="100%" class="add_border">
<img src="images/<%# Eval("status").ToString().Trim() %>_light_16.gif" alt="status" />
</td>
</tr>
<tr>
<td class="add_border_bold" nowrap">Short Title</td>
<td width="100%" class="add_border">
<%# Eval("short_title") %>
</td>
</tr>
</ItemTemplate>
</asp:FormView>
</asp:View>
<asp:View id="View2" runat="server">
<asp:FormView id="edit_program" runat="server">
<ItemTemplate>
<tr>
<td class="add_border_bold"nowrap">Status </td>
<td width="100%" class="add_border">
<asp:DropDownList id="p_status" runat="server"></asp:DropDownList>
</td>
</tr>
<tr>
<td class="add_border_bold" nowrap">Short Title</td>
<td width="100%" class="add_border">
<asp:TextBox runat="server" id="short_title" />
</td>
</tr>
</ItemTemplate>
</asp:FormView>
</asp:View>
</form>
with the following code behind page
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
namespace TM_non_deploy
{
public partial class Program : System.Web.UI.Page
{
protected Label Label1;
protected Person myPerson;
protected TestProgram myProgram;
List<TestProgram> program = null;
protected void Page_Load(object sender, EventArgs e)
{
try
{
myPerson = new Person("user");
myProgram = new TestProgram("999");
//needs to be done to refresh info on page
program = new List<TestProgram> { myProgram };
view_program.DataSource = program;
view_program.DataBind();
if (!IsPostBack)
{
//create controls and bind data
edit_program.DataSource = program;
edit_program.DataBind();
DropDownList p_status = edit_program.FindControl("p_status") as DropDownList;
p_status.Items.Add(new ListItem("Green"));
p_status.Items.Add(new ListItem("Yellow"));
p_status.Items.Add(new ListItem("Red"));
p_status.SelectedValue = myProgram.Status.Trim();
TextBox short_title = edit_program.FindControl("short_title") as TextBox;
short_title.Width = 200;
short_title.Text = myProgram.Short_Title.Trim();
}
}
catch (Exception ex)
{
Response.Write(ex);
Label1.Text = ex.ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View1);
save_button.Visible = false;
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View2);
save_button.Visible = true;
}
protected void Button3_Click(object sender, EventArgs e)
{
DropDownList c_status = edit_program.FindControl("p_status") as DropDownList;
myProgram.Status = c_status.SelectedValue;
bool update = myProgram.SaveTestProgram();
if (update)
{
Label1.Text = "Saved!";
//needs to be done to refresh info on page
program = new List<TestProgram> { myProgram };
view_program.DataSource = program;
view_program.DataBind();
MultiView1.SetActiveView(View1);
save_button.Visible = false;
}
else
{
Label1.Text = "Error Saving";
}
}
}
}
basically, it is one page that both displays the fields, and then on a button click displays the editable version of all those fields. my question is, should i be displaying all of the information like i am now, with evals? or should i switch to labels, or literals, or something else entirely? i want to know before i get too far and have to undo a lot of work.
there will end up being a ton of fields on this page, all types from checkboxes to dropdowns to multiline textboxes, so i want to make sure i pick the path that works best for displaying all of those different kinds of data, even though in this example i am only displaying small text information.

If you just need to display text, there's no reason not to just use your <%# Eval("title") %>
One thing that should be noted though, is that it's better to cast your DataItem and access the properties that way instead of Eval as Eval has to use reflection and is more costly (maybe to the being of actually being noticeable if you have a lot of stuff repeated).
Use: <%# (Container.DataItem as SomeObject).Title %> instead of <%# Eval("Title") %>
Kind of outside the scope of your question but just a side note. :)

I wouldn't go for ServerSide Controls (Labels/Literals) unless you need formatting or to change the control values in other server side events. They just add to ViewState (unless ViewState is disabled on those Controls).
Coming to whether it's the right approach, I would suggest you use EditItemTemplate of FormView instead of 2 FormViews in Different Views & a MultiView Control!

Related

Invalid postback or callback argument when navigating away from actively loading GridView

There are several posts on here with similar titles, but none that I have found actually exhibit the same behavior I'm seeing. I'm using buttons with MultiView as my navigation to give the appearance of tabs. The page loads, no problem. I can switch tabs, no problem. The issue I'm having occurs only when I press a different navigation button while a gridview is actively loading. If I wait for the gridview to fully load, I get no errors.
The full error I'm receiving is: Invalid postback or callback argument. Event validation is enabled using 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.
If I add the following, it does resolve my issue. However, I'm trying to avoid this if at all possible.
<%# Page ... EnableEventValidation = "false" />
default.aspx
<form id="form1" runat="server">
<table width="100%" align="center">
<tr style="background-color:#E9E9E9;">
<td>
<asp:Button Text="Tab1" BorderStyle="None" ID="Tab1Button" CssClass="Initial" runat="server"
OnClick="Tab1Button_Click" />
<asp:Button Text="Tab2" BorderStyle="None" ID="ConflictButton" CssClass="Initial" runat="server"
OnClick="ConflictButton_Click" />
<asp:Button Text="Tab3" BorderStyle="None" ID="Tab3Button" CssClass="Initial" runat="server"
OnClick="Tab3Button_Click" />
<asp:Button ID="AffiliateAddButton" runat="server" Text="Add" />
<asp:MultiView ID="MainView" runat="server">
<asp:View ID="View1" runat="server">
<table class="TabContent"><tr><td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true" DataSourceID="SqlDataSource1">
</asp:GridView>
</td></tr></table>
</asp:View>
<asp:View ID="View2" runat="server">
<table class="TabContent">
<tr>
<td>
View 2
</td>
</tr>
</table>
</asp:View>
<asp:View ID="View3" runat="server">
<table class="TabContent">
<tr>
<td>
View 3
</td>
</tr>
</table>
</asp:View>
</asp:MultiView>
</td>
</tr>
</table>
</form>
default.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Tab1Button.CssClass = "Clicked";
MainView.ActiveViewIndex = 0;
LoadGrid();
}
}
protected override void Render(HtmlTextWriter writer)
{
// Register controls for event validation
foreach (Control c in this.Controls)
{
this.Page.ClientScript.RegisterForEventValidation(
c.UniqueID.ToString()
);
}
base.Render(writer);
}
private void LoadGrid()
{
SqlDataSource1.CancelSelectOnNullParameter = false;
GridView1.DataSourceID = null;
GridView1.DataSourceID = "SqlDataSource1";
GridView1.DataBind();
}
private void ButtonsControl(string tab)
{
if(tab == "Tab1")
{
AffiliateAddButton.Visible = true;
Tab1Button.CssClass = "Clicked";
ConflictButton.CssClass = "Initial";
Tab3Button.CssClass = "Initial";
LoadGrid();
}
if (tab == "Tab2")
{
AffiliateAddButton.Visible = false;
Tab1Button.CssClass = "Initial";
ConflictButton.CssClass = "Clicked";
Tab3Button.CssClass = "Initial";
GridView1.DataSourceID = null;
GridView1.DataBind();
}
if (tab == "Tab3")
{
AffiliateAddButton.Visible = false;
Tab1Button.CssClass = "Initial";
ConflictButton.CssClass = "Initial";
Tab3Button.CssClass = "Clicked";
GridView1.DataSourceID = null;
GridView1.DataBind();
}
}
protected void Tab1Button_Click(object sender, EventArgs e)
{
ButtonsControl("Tab1");
MainView.ActiveViewIndex = 0;
}
protected void ConflictButton_Click(object sender, EventArgs e)
{
ButtonsControl("Tab2");
MainView.ActiveViewIndex = 1;
}
protected void Tab3Button_Click(object sender, EventArgs e)
{
ButtonsControl("Tab3");
MainView.ActiveViewIndex = 2;
}
What I ended up doing was two things:
Added paging. Ideally I didn't want this in this specific scenario but limiting my page to 500 lines made it load fast enough to almost eliminate this.
Switched from multiview to frameset. Again, not an ideal option, but works in my given scenario.

Showing buttons if list view is empty

I have a list view which retrieves the data from sql data source. I am trying to make two buttons(Yes and No) and a label outside the list view visible only if the list view is not empty. The process is: a person enter the information into text boxes and click the button retrieve, if the entered data exists in the database, the list view shows certain information.
I have the following code:
protected void btnExistingRetrive_Click(object sender, EventArgs e)
{
if (lstExisting.Items.Count>0 )
{
lblIsITYou.Visible = true;
btnYes.Visible = true;
btnNo.Visible = true;
}
}
By default buttons and the label are not visible.
The problem is when i click on retrieve button it shows me the list view with the information but buttons a the label are still not visible. They became visible only when i double click the retrieve button. Please tell me what is my mistake?
Thank you
Use the ListView EmptyDataTemplate
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
runat="server">
<LayoutTemplate>
<table runat="server" id="tblProducts">
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:Label ID="FirstNameLabel" runat="Server" Text='<%#Eval("FirstName") %>' />
</td>
<td>
<asp:Label ID="LastNameLabel" runat="Server" Text='<%#Eval("LastName") %>' />
</td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<table class="emptyTable" cellpadding="5" cellspacing="5">
<tr>
<td>
<asp:Image ID="NoDataImage"
ImageUrl="~/Images/NoDataImage.jpg"
runat="server"/>
</td>
<td>
No records available.
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:ListView>
do you bind listview before checking the items count?
Do this on postback instead of in the event.
In your Page_Load do something like this:
protected void Page_Load(object sender, EventArgs e)
{
bool visible = (lstExisting.Items.Count > 0); // assuming it's never null
lblIsITYou.Visible = visible;
btnYes.Visible = visible;
btnNo.Visible = visible;
}
If the above creates complications then do as I said first with postback:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
bool visible = (lstExisting.Items.Count > 0); // assuming it's never null
lblIsITYou.Visible = visible;
btnYes.Visible = visible;
btnNo.Visible = visible;
}
}

Localization inside an ascx user control

----------------OLD CODE ----------------------------------------------
I have create a user control, which is a Main Menu, that has to be localized. So I have created 3 resource files inside the App_LocalResources, and I have a dropdown to change the languages selected.
The Main Menu looks like this :-
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="MainMenu.ascx.cs" Inherits="GGX4._2.MainMenu" %>
<div>
<asp:DropDownList ID="ddlLangs" runat="server"
onselectedindexchanged="ddlLangs_SelectedIndexChanged" AutoPostBack="True" meta:resourcekey="ddlLangsResource1">
<asp:ListItem Text="English" Value="en-US" meta:resourcekey="ListItemResource1"></asp:ListItem>
<asp:ListItem Text="German" Value="de-DE" meta:resourcekey="ListItemResource2"></asp:ListItem>
<asp:ListItem Text="Spanish" Value="es-ES" meta:resourcekey="ListItemResource3"></asp:ListItem>
</asp:DropDownList>
</div>
<div>
<table>
<tr>
<td width="100%" nowrap height="16">
<img border="0" src="Images/GREENSQUARE.gif" width="16" height="16"><b><font size="2" face="Arial">
<asp:HyperLink ID="hypIntroduction" runat="server" NavigateUrl="Overview.htm"
meta:resourcekey="hypIntroductionResource1" >[hypIntroduction]</asp:HyperLink>
</tr>
<tr>
<td width="100%" nowrap height="16">
<img border="0" src="Images/GREENSQUARE.gif" width="16" height="16"><b><font size="2" face="Arial">
<asp:HyperLink ID="hypGlobalGradingMethodology" runat="server" NavigateUrl="GGMethodology.htm"
meta:resourcekey="hypGlobalGradingMethodologyResource1" >[hypGlobalGradingMethodology]</asp:HyperLink>
</td>
</tr>
<tr>
<td width="100%" nowrap height="16">
<img border="0" src="Images/Redsquare.gif" width="16" height="16"><b><font size="2" face="Arial">
<asp:HyperLink ID="hypDeterminingBusiness" runat="server"
NavigateUrl="ScopematrixGeneral.htm"
meta:resourcekey="hypDeterminingBusinessResource1">[hypDeterminingBusiness]</asp:HyperLink>
</td>
</tr>
<tr>
<td width="100%" nowrap height="16"><font size="2" face="Arial">
<img border="0" src="Images/BLUEBULLET.gif" width="16" height="16">
<asp:HyperLink ID="hypMethodology" runat="server"
NavigateUrl="methodology.htm"
meta:resourcekey="hypMethodologyResource1">[hypMethodology]</asp:HyperLink>
</font>
</td>
</tr>
</table>
</div>
and in the code behind I have the following :-
string defaultLanguage = Thread.CurrentThread.CurrentUICulture.ToString();
protected void Page_Load(object sender, EventArgs e)
{
this.InitializeCulture();
}
protected void InitializeCulture()
{
if (String.IsNullOrEmpty(CurrentCulture))
{
CurrentCulture = defaultLanguage;
}
if (!String.IsNullOrEmpty(CurrentCulture))
{
try
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(CurrentCulture);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
}
catch
{
throw;
}
}
}
public String CurrentCulture
{
get
{
if (null != Session["PreferedCulture"])
return Session["PreferedCulture"].ToString();
else
return "en-US";
}
set
{
Session["PreferedCulture"] = value;
}
}
protected void ddlLangs_SelectedIndexChanged(object sender, EventArgs e)
{
Session["PreferedCulture"] = ddlLangs.SelectedValue;
InitializeCulture();
}
However when I do the change in the dropdownlist, the Culture reamins the same. Normally when applied to a System.Web.UI.Page, I would override the InitializeCulture(), however I cannot find a way to do it in the ascx.
How can I achieve that?
Thanks for your help and time
-------------NEW CODE-----------------------------------------------
I have decided to make things simpler, and I have managed to achieve what I want, however with a page refresh which I do not like at all and wish to make without.
So basically I have created a simple example that is working now :-
The Site.Master just has the drop-down as the extra code :-
<div>
<asp:DropDownList ID="ddlLangs" runat="server" onselectedindexchanged="ddlLangs_SelectedIndexChanged" AutoPostBack="True"
meta:resourcekey="ddlLangsResource1">
<asp:ListItem Text="English" Value="en-US"
meta:resourcekey="ListItemResource1" ></asp:ListItem>
<asp:ListItem Text="German" Value="fr-FR" meta:resourcekey="ListItemResource2" ></asp:ListItem>
<asp:ListItem Text="Spanish" Value="it-IT"
meta:resourcekey="ListItemResource3" ></asp:ListItem>
</asp:DropDownList>
</div>
and the code behind looks like this:-
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["PreferredCulture"]!= null)
ddlLangs.SelectedValue = Session["PreferredCulture"].ToString();
}
}
protected void ddlLangs_SelectedIndexChanged(object sender, EventArgs e)
{
Session["PreferredCulture"] = ddlLangs.SelectedValue;
Server.Transfer(Request.Path);
}
The Default.aspx has the MainMenu UC, and a sample label, however it inheris from the BasePage :-
<asp:Content ID="MenuContent" runat="server" ContentPlaceHolderID="MainMenuContent">
<uc:MainMenu runat="server" ID="ucMainMenu" />
Welcome to ASP.NET!
</asp:Content>
And the BasePage has the code to Initialize the Culture
I wish to get rid of the Server.Transfer(Request.Path), and avoid refreshing the page, however I have not found out a method yet.
Any help/ideas will be very much appreciated!
Thanks
InitializeCulture() method execute earlier in Page life cycle, hence the culture you are setting in this method is old one..not the one user has selected..so you have to request a page again to set the culture user has selected.that's what you doing by Server.Transfer(Request.Path)..
if you want to avoid 'Server.transfer'.. you need get the new value of culture during InitializeCulture() method execution and assign that new value. here is the link this shows you how to retrieve new value during InitializeCulture() method execution.
Hope this helps..
This is quite an old post, but since localization can be a bit tricky, I have some tips.
For each page, you need to override web.ui.page with the code below. So what I do is create a new class that inherits from web.ui.page and have the aspx pages inherit from that new class: In this case PortalPage.
public class PortalPage:System.Web.UI.Page
{
protected override void InitializeCulture()
{
string _language = (string)Session["Language"];
if (_language == null)
{
_language = ConfigurationManager.AppSettings["DefaultLanguage"];
Session["Language"] = _language;
}
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(_language);
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(_language);
base.InitializeCulture();
}
}
Next, instead of inheriting your webpages from System.Web.UI.Page inherit from your new class. In this example: PortalPage
public partial class pages_Databases : PortalPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Then put all resource files (.resx) in the appropriate subfolders (App_LocalResources) and make sure, your resx file names match your webcontrols.
Finally: Recompile! or rebuild! Your webcontrols will not be refreshed / show results without.

Read textbox value from asp.net and pass it to c# variable

I have a page with a with a form i when i fill the form i want to access that form data in my c# codebehind file.
Register.aspx:
<%# Page Title="Home" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="True" CodeBehind="Register.aspx.cs" Inherits="Informito._Default" %>
<div>
<table class="style1">
<tr>
<td>Utilizador:</td>
<td><asp:TextBox ID="Utilizador" name="Utilizador" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Password:</td>
<td><asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox></td>
</tr>
</table>
</div>
<asp:Button ID="Button1" runat="server" Text="Registar" OnClick="Registar"/>
Register.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.SqlClient;
using Informito.Admins;
namespace Informito
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void Registar(object sender, EventArgs e)
{
string Username = Utilizador.Text; //Error here: Object reference not set to an instance of an object.
string Password= Password.Text;
RegisterUser(Username, Password, 1);
}
}
}
Register.aspx.designer.cs:
namespace Informito {
public partial class _Default {
protected global::System.Web.UI.WebControls.LoginView LoginView1;
protected global::System.Web.UI.WebControls.TextBox Utilizador;
protected global::System.Web.UI.WebControls.TextBox Password;
}
}
What function i have to use to read from a asp.net textbox and pass it to by c# codebehind variable?
UPDATE:
You need to enclose your markup in <asp:Content></asp:Content> tags because you are using a master page.
If you have used Visual Studio to generate your web project, then you can see Register.aspx.designer.cs which should have code like below. If you don't then add it in the class (you can add it in Register.aspx.cs or Register.aspx.designer.cs).
protected global::System.Web.UI.WebControls.TextBox Utilizador;
Then you can use
string UserName = Utilizador.Text;
UPDATE:
I just tried this and seems to work fine:
Register.aspx.cs
public void Registar(object sender, EventArgs e)
{
string Username = Utilizador.Text;
string PassWd = Password.Text;
RegisterUser(Username, PassWd, 1);
}
Register.aspx.designer.cs
public partial class _Default {
protected global::System.Web.UI.WebControls.TextBox Utilizador;
protected global::System.Web.UI.WebControls.Button Button1;
protected global::System.Web.UI.WebControls.TextBox Password;
}
Register.aspx
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Register.aspx.cs" Inherits="Informito._Default" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div>
<table class="style1">
<tr>
<td>Utilizador:</td>
<td><asp:TextBox ID="Utilizador" name="Utilizador" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Password:</td>
<td><asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox></td>
</tr>
</table>
</div>
<asp:Button ID="Button1" runat="server" Text="Registar" OnClick="Registar"/>
</asp:Content>
Make sure your code inside a <form runat="server"></form> tag?
Your code should look like:
<form runat='server' id="form1">
<div>
<table class="style1">
<tr>
<td>Utilizador:</td>
<td>
<asp:TextBox ID="Utilizador" name="Utilizador" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Password:</td>
<td><asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox></td>
</tr>
</table>
</div>
<asp:Button ID="Button1" runat="server" Text="Registar" OnClick="Registar"/>
</form>
EDIT
To reference controls in a master page/content placeholder

FindControl can't find a control

I have a problem with FindControl function. The problem is as follow:
aspx:
<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<table class="inputTable">
<tr><td>
<asp:CheckBox ID="Extern" AutoPostBack="True" OnCheckedChanged="OnCheckedChangedMethod" runat="server" />
</td><td>Externes Unternehmen</td></tr>
<tr>
<td>
<asp:TextBox ID="Firmierung" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="Firmierung" Display="Dynamic"
ErrorMessage="RequiredFieldValidator"
Text="Bitte geben Sie die Firmierung ein."></asp:RequiredFieldValidator>
</td>
</tr>
</table>
aspx.cs:
protected void OnCheckedChangedMethod(object sender, EventArgs e)
{
if (Extern.Checked)
{
Control ctr = FindControl("RequiredFieldValidator1");
if (ctr != null)
{
ctr.Visible = false;
}
}
else
{
}
}
But FindControl didn't work, it couldn't find that control. Was I wrong at any point?
Thanks in advance.
ASP.NET creates a field for you, as it is located inside a Content: this.RequiredFieldValidator1 in your page.
The FindControl way would be like this (find it in the master page's content panel):
Control ctr = Master.FindControl("MainContent")
.FindControl("RequiredFieldValidator1");
Based on your limited source, you should be able to simplify your code behind method to:
protected void OnCheckedChangedMethod(object sender, EventArgs e)
{
this.RequiredFieldValidator1.Visible = this.Extern.Checked;
}
There should be no need for the use of FindControl().
When you type "this.", if you don't see RequiredFieldValidator1 appear in your intellisense, and assuming you are using ASP.NET 2.0 or greater, check your VS.NET warnings to see if your .aspx has a warning message with an associated "Generation of designer file failed". If so, you must correct the warning.

Categories

Resources