Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
ASP .Net
Event Hander for OnCheckChanged Event for a CheckBox Template Field
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="David Johnston, post: 4205589"] First, let me say I am relatively new to ASP.NET ... most .NET experience is with C# (Winforms). Now, I have a web page with a gridview that contains a checkbox control in a template field (see definition below): <asp:TemplateField ConvertEmptyStringToNull="False" HeaderStyle-CssClass="header" HeaderText="Select"> <ItemTemplate> <asp:CheckBox ID="chkSelectAgent" runat="server" OnCheckedChanged="chkSelectAgent_CheckChanged" /> </ItemTemplate> </asp:TemplateField> On the same page, I have a list box control. When the check box on a given row is clicked, I want to populate a row in the list box. My event handler is listed below: Public Sub chkSelectAgent_CheckChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSelectAgent.CheckedChanged Dim sAgentId As String Dim sFirst As String Dim sLast As String Dim chkSelectedAgent As CheckBox Dim gvrSelectedAgent As GridViewRow If TypeOf sender Is CheckBox Then chkSelectedAgent = DirectCast(sender, CheckBox) If chkSelectedAgent.Checked Then gvrSelectedAgent = DirectCast(chkSelectedAgent.Parent.Parent, GridViewRow) sAgentId = gvrSelectedAgent.Cells(1).Text sFirst = gvrSelectedAgent.Cells(2).Text sLast = gvrSelectedAgent.Cells(3).Text lbSelectedAgents.Items.Add(sFirst + " " + sLast + " (Agent ID: " + sAgentId + ")") End If End If End Sub When I set a breakpoint in the event handler, it does hit the breakpoint, but only when I go to another page, not when I click in a check box. Do I need to set AutoPostBack="true" for the checkbox column? When I tried that, my page no longer renders. I'm guessing that is because I haven't handled the postback in the Page_Load subroutine. So, I have two questions: 1) Why isn't the event hander being fired when I click the checkbox? 2) If AutoPostBack is needed, why doesn't anything get rendered on the postback (not even labels and text boxes)? I have googled this like crazy and haven't found a definitive answer. If you have any good informational links, I not only want to solve the problem, but also to learn in the process. Thanks in advance for any help you can provide. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
ASP .Net
Event Hander for OnCheckChanged Event for a CheckBox Template Field
Top