Web.UI.Controls.TextBox
in my aspx page i have used-
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="tmaintextchanged" ></asp:TextBox>
in my code behind :
<asp:Label ID="show" runat="server" ></asp:Label >
protected void tmaintextchanged(object sender, EventArgs e)
{
show.Text = "working";
}
when I am executing this ,Why is the text of label "show" not changing.Kindly help. Am i missing any configuration to the Text box.
You need to set autopostback on TextBox control:
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="tmaintextchanged" ></asp:TextBox>
Update
see this post:
How do I make a Textbox Postback on KeyUp?
Related
How do I open DropDown of RadComboBox on asp:Button click? Both RadComboBox and Button are inside EditItemTemplate of RadGrid.
My requirement is: I had to open DropDown of RadComboBox ("ddlAccountCode" in below HTML code) on a click of button ("btnSearch" in below HTML code).
Below is the HTML code of RadComboBox and Button
<telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
<ItemTemplate>
<asp:Label ID="lblAcCode" runat="server" Text='<%# Eval("AccountCode")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>
<telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="240" DropDownWidth="310" HighlightTemplatedItems="true" CausesValidation="true"
OnItemsRequested="ddlAccountCode_ItemsRequested" EnableItemCaching="true" ShowDropDownOnTextboxClick="false" EnableLoadOnDemand="True" ShowMoreResultsBox="true" EnableVirtualScrolling="true" MarkFirstMatch="True" AllowCustomText="true"
Filter="Contains" AppendDataBoundItems="true" DataTextField="AccountDescription" DataValueField="AccountCodeID" AutoPostBack="true" OnSelectedIndexChanged="ddlAccountCode_SelectedIndexChanged">
</telerik:RadComboBox>
<telerik:RadButton id="btnSearch" runat="server" text="Search" OnClick="btnSearch_Click">
</telerik:RadButton>
</EditItemTemplate>
</telerik:GridTemplateColumn>
I am doing searching/filtering in RadComboBox on a button click. All is working fine except when I type/search anything in textbox of RadComboBox and click on button to search, the dropdown of RadCombo does not open up. Due to this, every time, I have to manually open the dropdown to see the result of searched text in RadComboBox.
Below line of code is working fine for my requirement:
protected void btnSearch_Click(object sender, EventArgs e)
{
GridEditableItem editedItem = (sender as Button).NamingContainer as GridEditableItem;
RadComboBox combo = (RadComboBox)editedItem.FindControl("ddlAccountCode");
combo.OpenDropDownOnLoad = true; // opens dropdown of RadComboBox
}
I have the following code in my .aspx file:
<asp:TextBox ID="txtSearch" runat="server" Width="278px"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" AutoPostBack="true" />
When I click on the btnSearch button it does an AutoPostBack.
What my goal is that if btnSearch was clicked, I would then capture the value of txtSearch or else I would not
How do I code such that if btnSearch was clicked on AutoPost I can flag it.
First, a Button does not have an AutoPostBack property. It posts back always.
Second, you can simply handle it's Click event and read the txtSearch.Text property:
<asp:TextBox ID="txtSearch" runat="server" Width="278px"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
codebehind:
protected void btnSearch_Click(Object sender, EventArgs e)
{
string search = txtSearch.Text;
// ...
}
I have an update panel, and inside the update panel there is a dropdown and a required field validator which is associated with the dropdown and the autopostback of dropdown set to true.
now whenever user change the option the autopost back occure in updatepanel.. what i need is that if user pick the empty item from the dropdown it should not postback to the server and validator should fire.... but in my case the validators fire perfecty and also there is a postback and after the postback the required field validaor state is true.
what i need is to stop the postback if validator fails.
i have search for this problem alot but doe's not find any thing helpful.
1- In DropDownList:
CausesValidation="True"
2- In Page_Load use string.Empty to value of first item:
DropDownList1.Items.Add(new ListItem("Select...", string.Empty));
ASPX:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
CausesValidation="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="DropDownList1" Display="Dynamic" ErrorMessage="Empty"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="Label1" runat="server" EnableViewState="False"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
Code behind:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = DropDownList1.SelectedItem.Text;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Add(new ListItem("Select...", string.Empty));
DropDownList1.Items.Add(new ListItem("mehdi", "1"));
DropDownList1.Items.Add(new ListItem("ali", "2"));
}
}
I have this HTML.
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
<asp:FormView ID="FormView2" runat="server" DefaultMode="Insert" DataSourceID="SqlDataSource2">
<asp:TextBox runat="Server" Text='<%# Eval("Terms") %>'></asp:TextBox>
</asp:FormView>
</asp:FormView>
The code above works without any error but I want to get terms in the textbox fetched from SqlDataSource1 of FormView1 instead of FormView2 (SqlDataSource2). What I am missing here?
You can access the value of Parent formView DataSource value in child formview as what you are currently doing. But there is another way you set value. like..
protected void ChildFormWiew_DataBound(object sender, EventArgs e)
{
if (ChildFormView.CurrentMode == FormViewMode.Edit)
{
TextBox txtTemrs = ParentFormView.FindControl("Terms") as TextBox;
((TextBox)ChildFormView.FindControl("Terms")).Text = txtTemrs.Text;
}
}
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ProductId") %>'>
</asp:TextBox>
</InsertItemTemplate>
How do I pass a value to the Bind("ProductId")? More specifically:
Request.QueryString["ProductId"]
EDIT:
leave it with your original bind but add OnDataBinding
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ProductId") %>'
OnDataBinding = "TextBox1_OnDataBinding"></asp:TextBox>
and
protected void TextBox1_OnDataBinding(object sender, EventArgs e)
{
(sender as TextBox).Text = Request.QueryString["ProductId"];
}
In addition to
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Request.QueryString["ProductID"]%>' />
You need to handle the OnInserting event of your datasource and set the value there with the querystring parameter.
You will have to explicitly set the TextBox value in the DataBound event of your DataBoundControl (repeater/gv etc).