Reputation: 1975
In the below code Changing asyncPostBackTrigger to PostBackTrigger causing the entirepage postback.
But the below code is not at all doing anything when we use the trigger as asyncPostBackTrigger.
Any suggestions about what I am doing wrong??
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" ID="UpdatePanel_1" >
<ContentTemplate>
<asp:CheckBox ID="chkNotKnown" runat="server" AutoPostBack="True"
Text="(Not Known)" OnCheckedChanged="chkNotKnown_CheckedChanged"/>
</ContentTemplate>
<Triggers>
<asp:asyncPostBackTrigger ControlID="chkNotKnown"/>
</Triggers>
</asp:UpdatePanel>
<asp:TextBox ID="txtDrCode" runat="server" OnFocus="this.style.borderColor='red'" OnBlur="this.style.borderColor=''"></asp:TextBox>
</form>
</body>
</html>
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub chkNotKnown_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkNotKnown.CheckedChanged
With txtDrCode
If chkNotKnown.Checked Then
.Text = "Not Known"
.Enabled = False
Else
.Text = ""
.Enabled = True
End If
End With
End Sub
End Class
Upvotes: 0
Views: 2624
Reputation: 35514
The chkNotKnown
is inside the UpdatePanel, while txtDrCode
is outside of it. Also you specify chkNotKnown
as an asyncPostBackTrigger
, which is the same as something already present in the UpdatePanel.
So either change the Trigger to a PostBackTrigger
(causing a full PostBack)
<Triggers>
<asp:PostBackTrigger ControlID="chkNotKnown" />
</Triggers>
Or place the TextBox inside the UpdatePanel
<asp:UpdatePanel runat="server" ID="UpdatePanel_1">
<ContentTemplate>
<asp:CheckBox ID="chkNotKnown" runat="server" AutoPostBack="True"
Text="(Not Known)" OnCheckedChanged="chkNotKnown_CheckedChanged" />
<asp:TextBox ID="txtDrCode" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
Upvotes: 1