DataList and Checkbox - asp.net

I have checkbox in the DataList. Now I need to execute a code-behind when the checkbox is ticked. As far as I know the itemcommand in datalist will not triggered when the checkbox is ticked. I even tried to put the onCheckChanged event in the checkbox but it even worse the situation (not just does not trigger the event but also does allow me to tick the checkbox at all).
Does anyone has a solution?
thanks

I just created a DataList with a CheckBox in it like this:
<asp:DataList ID="Datalist1" runat="server" DataSourceID="Sqldatasource1">
<ItemTemplate>
<asp:CheckBox ID="Checkbox1" Text="text" runat="server" OnCheckedChanged="Checkbox1_CheckedChanged" AutoPostBack="true" />
</ItemTemplate>
</asp:DataList>
and this code-behind
protected void Checkbox1_CheckedChanged(object sender, EventArgs e)
{
}
That allowed me to break into the CheckedChanged event without any problem.

Are you setting AutoPostBack="true" on the <asp:CheckBox control? It might fire the ItemCOmmand event, otherwise, you would have to tap into the CheckChanged event for the control on ItemCreated event.

Related

Radio Button Check Changed even not firing

I've 2 radio buttons in a user control and control is registered to the page. When i click on the radio button, the event(CheckChanged) is not firing.
<asp:View ID="viewfirst" runat="server">
<asp:UpdatePanel ID="updatepanel1" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:RadioButton ID="radio1" Text="Yes" Enabled="true" runat="server" />
<asp:RadioButton ID="radio2" Text="No" Enabled="true" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:View>
Below is code in behind file of the control.
Protected Sub radio1_CheckedChanged(sender As Object, e As EventArgs) Handles radio1.CheckedChanged
//
//
End Sub
It seems everything looks good, but something is wrong. Can you please let me know.
Set autopostback=true for checkbox - This will trigger the event
UpdateMode=conditional and ChildrenAsTriggers=false for the UpdatePanel - so when you trigger checkbox, it won't trigger full postback
You have to set the event handler of each radio button to OnCheckChanged and put them in the same RadioGroup (GroupName) so they do not fire together. Remember to set AutoPostBack = true for each radio button. Set only one radioButton as checked = true. I can see your code has both checked. Something like this...
The aspx page:
<asp:RadioButton id="radioButton1" runat="server" GroupName="btnGrp" Text="Button 1" AutoPostBack="true" Checked="true" OnCheckedChanged="radioButton1_CheckedChanged"></asp:RadioButton>
<asp:RadioButton id="radioButton2" runat="server" GroupName="btnGrp" Text="Button 2" AutoPostBack="true" OnCheckedChanged="radioButton2_CheckedChanged"></asp:RadioButton>
The code-behind (aspx.cs) page:
protected void radioButton1_CheckedChanged(object sender, EventArgs e)
{
// Your code here
}
protected void radioButton2_CheckedChanged(object sender, EventArgs e)
{
// Your code here
}
Hope this helps!

Postback of one dropdown fires selectedindexchanged event of all all remaining dropdown

Example:
<asp:DropDownList runat="server" AutoPostBack="true" ID="ddlSample">
<asp:ListItem Text="text1" />
<asp:ListItem Text="text2" />
</asp:DropDownList>
Now if change the item in the above dropdown it will cause all the other dropdowns postback events to fire.
Like
<asp:DropDownList EnableViewState="true" ID="ddlNewSelec" runat="server"
AutoPostBack="true" OnSelectedIndexChanged="ddlNewSelec_SelectedIndexChanged">
<asp:ListItem Text="--Select Test Type--" Value="" />
</asp:DropDownList>
Details:
The Page has ViewState disabled. I try enabling viewstate for the individual dropdowns but it does not matter.
Any idea why this is happeing.
Let me know if you need any more details
EDIT:
The dropdown fires the selectedindexchanged event of all other dropdowns on the form. The dropdown named as ddlSample is doing nothing just causing postback but why the selectedindexchanged evenet of other dropdowns fired up.
Additional Info:
All the inputs are in updatePanel and removing them does not make any effect.
In Page Load i am not doing anything on postback
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindSomeDDLs();
}
}
You didn't bind the SelectedIndexChanged event on the "ddlSample" dropdown. Please try binding that property like so..
<asp:DropDownList ID="ddlSample" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlSample_SelectedIndexChanged">
<asp:ListItem Text="text1" />
<asp:ListItem Text="text2" />
</asp:DropDownList>
The answer seems to be very weird but this is true.
This is happening just because of EnableViewState property set to false.

ModalPopUp Displaying after LinkButton Postback

After spending hours on it i still couldnt find the Solution,Plaese Help.
I am Developing a Website where I have a Gridview with data,i have a linkbutton as a templatefield in one of the Columns which onClick is doing a postback and displaying the records in a modalpoupextender,which is inside a seperate asp panel,
i have edit,update,delete buttons in that popup which are doing postback and functioning well.
Remmember i have not used UpdatePanel anywhere,as i do not have that kind of requirement.
Now,i have another LinkButton on the Page(not in gridview),which has some other functinality after OnClick postback,the problem is When i Click That LinkButton it first displays the ModalpopUp and then it does the postback and completes the function.The important part is that the Modal PopUp disappears just in seconds.
So,i just get a glimpse of Modalpopup whenever i click on the LinkButton.
I tried ModalPopUpExtender1.hide() at every Possible Place,but its not Working.
I am not sure how to disable that popup from appearing on LinkButton Click.Please Help me on it.I am in Trouble.
Thanks in Advance.
Here is my GridView Code:
<asp:GridView ID="dg_Task" runat="server" CssClass="gridview"
BorderWidth="1px"
Font-Names="Trebuchet MS" Font-Size="Small" AllowSorting="True"
AutoGenerateColumns="False" onrowdatabound="dg_Task_RowDataBound"
Width="100%" Height="143px"
onprerender="mergeDoc">
<Columns>
<asp:TemplateField HeaderText="Task">
<ItemTemplate>
<asp:Label ID="lbl_tid" runat="server" Text='<%#Bind("ID") %>'
Visible="False"></asp:Label>
<asp:LinkButton runat="server" ID="Lnk" ForeColor="Black"
CommandArgument='<%# Bind("ID") %>' Font-Underline="False" onclick="Title_Click"
Text='<%# Bind("Task") %>' Font-Names="Trebuchet MS"></asp:LinkButton>
</ItemTemplate>
<HeaderStyle Width="35%" />
<ItemStyle Height="2px" HorizontalAlign="Left" VerticalAlign="Top" />
</asp:TemplateField>
Here is The CodeBehind:
protected void Title_Click(object sender, EventArgs e)
{
ddown_status.Items.Clear();
var btnId = sender as LinkButton;
string id = btnId.CommandArgument;
btnUpdate.CommandArgument = id.ToString();
btnDelete.CommandArgument = id.ToString();
//Some Code which fills the details of my PopUp Fields
this.modalPopUpExtender1.Show();
}
Here is the another LinkButton(On Main Page) code:
protected void LinkButton1_Click(object sender, EventArgs e)
{
//here even i simple postback(Without any code) Triggers The PoPUp and Provides a Glimpse then the rest code runs
//sample code here
}
Please Help .Thanks

How to access "textChanged" event from text box that added to telerik Rad Grid?

Hi There Do you know how to access textboxes textChanged event added to a radgrid that are bound but are used to trap any row related input a user typed in to the textbox for that column. I need to access this data server side when a postback occurs. Your thoughts are greatly appreciated Thanking you
Being in a RadGrid really doesn't change much. Set AutoPostBack="true" on the TextBox, and create an OnTextChanged event handler:
<telerik:RadGrid ID="RadGrid1" runat="server">
<MasterTableView AutoGenerateColumns="false">
<Columns>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
In code-behind:
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
TextBox txt = sender as TextBox;
if (txt != null)
{
//some logic here
}
}

OnTextChanged event is not firing

I have a TextBox inside my .Aspx page:
<ajax:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtCity" AutoPostBack="true" OnTextChanged="txtCity_TextChanged"
Width="90%" runat="server" ></asp:TextBox>
</ContentTemplate>
</ajax:UpdatePanel>
Code behind:
protected void txtCity_TextChanged(object sender, EventArgs e)
{
lblMessage.Text = "you have typed:" + txtCity.Text;
}
And for lblMessage [on the same .Aspx page]:
<ajax:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblMessage" runat="server" Text="" ></asp:Label>
</ContentTemplate>
</ajax:UpdatePanel>
But when I am typing in the TextBox. lblMessage is not updating.
How to rectify this?
It sounds like you're thinking that the OnTextChange event is fired while you are typing in the text box. This is not true. OnTextChange is a server-side event and only fires when the page (or panel) is posted back. Typing into a text box on a page does not post the page back and so this event will only fire once you submit the form.
What you would actually want to do in this case, is to use some JavaScript with the onkeypress JavaScript event to update the label text as things are typed into the TextBox. JavaScript is run on the client and doesn't require you to post back the page in order for it to run.

Resources