.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How come I can't set focus to a textbox in DetailsView?

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :ASP.Net
Here's the first part of a DetailsView control definition:          <asp:DetailsView ID="DetailsView1" runat="server" DefaultMode="Edit" AutoGenerateRows="False" Width="100%" BorderColor="Silver">            <RowStyle Height="25px" />            <Fields>              <asp:TemplateField HeaderText="Name" SortExpression="Name">                <EditItemTemplate>                  <asp:TextBox ID="textBoxName" runat="server" Text='<%# Bind("Name") %>' CssClass="detailsTextBox" onclick="SelectText2(this)" onKeyUp="EnableSubmit()" />                </EditItemTemplate>                <InsertItemTemplate>        &nb

View Complete Post

More Related Resource Links

Issue accessing textbox controls nested within a DetailsView within an UpdatePanel

I have a couple of textboxes nested with a detailsview, within an updatepanel.  When I try and access them from the code behind, it returns a null value as if they don't exist.  Can't figure out why that would be.ASPX code is: <asp:UpdatePanel ID="upSpecificShout" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" > <ContentTemplate> <asp:DetailsView ID="dvSingleShout" DataSourceID="sdsSingleShout" runat="server" AutoGenerateRows="false" OnDataBound="SetDVIcons" HeaderStyle-CssClass="noDisplay" > <EmptyDataTemplate> <p class="Watermark"> The panel on the left shows a list of everything you've shouted. (Your replies to other shouts are highlighted in blue/green.) </p> <p class="Watermark"> This right hand panel will show specific shouts with a list of replies etc.. Just do a little click on a shout title to display more detail here. </p> <p class="Watermark">

why isnt the focus being set to a textbox in the gridview?

Hi, i have a gridview with textboxes in. a barcode reader is used to enter data in the textboxes in the grid. when something is scanned in the page does a full postback. so after a postback and after something has been scanned in, i want the focus to be moved to the next textbox in the row inside the gridview.  i have some code, but it doesnt seem to work. after the postback the focus is set to one of the textboxes outside the grid. i need it to recognise one of the textboxes in the grid. i have tried to use the findcontrol property to do this still doesnt work. please can anyone see where i am going wrong. what i wanted to do is for it to automatically tab to the next textbs in the gridview after a postback. please any advise on this would be much appreciated. thank you very muchprotected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { WebControl wcICausedPostBack = (WebControl)GetControlThatCausedPostBack(sender as Page); int indx = wcICausedPostBack.TabIndex; var ctrl = from control in wcICausedPostBack.Parent.Controls.OfType<WebControl>() where control.TabIndex > indx select control; ctrl.DefaultIfEmpty(wcICausedPostBack).First().Focus(); } } protected Control GetControlThatCausedPostBack(Page page)

textbox focus problem


I have a textbox (txtMaiden) and a radio button list (rblGender) in two separate User Controls that I'm using for a registration site. The txtMaiden control appears or disappears depending on whether Male or Female is designated on the radio button. This all works fine but I want the textbox to have focus when it becomes visible. As of now, it only gets focus when the page refreshes. Code follows. Any ideas?

<Prf:gender ID="GenderE" Gender='<%#Bind("Gender")%>' runat="server" />
<Prf:maiden ID="MaidenE" Maiden='<%#Bind("MaidenName")%>' Maiden_Disp='<%#Bind("MaidenName_Disp")%>'
    runat="server" />

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="gender.ascx.vb" Inherits="userControls_profile_gender" %>
<asp:Panel ID="pnlGender" Visible="true" runat="server">
    <div class="label">
        <asp:Label ID="lblGender" Text="Sex:" runat="server" />
    <div class="ctrl">
                <asp:RadioButtonList ID="rblGender" AppendDataBoundItems="True" AutoPostBack="True"

Time added to Detailsview TextBox Date only field


Does anyone know why a time stamp is added to a textbox field that is bound to a SQL 2008 date datatype field?

I can view the data in the database and, as expected, it only contains a date. When I bind the textbox to the db field it tacks the time '12:00:00 AM' to the end of the date?


keep focus on textbox on textchange event



How can I keep focus on caller textbox on textchange event or set focus on a given textbox according to a given value?

How can I know which textbox triggered the event if I need to use the same textchange method?

thanks in advance

Silverlight - Textbox on focus wait till a Asynchronous process is complete



I have a textbox, where i call its lostfocus event when the value changes.

In lost focus i do a Asynchronous process to update a grid with the text entered. 

I have a scenario in which immediately after changing the value in textbox i hit a button, though the button click event raises i want it to wait till the asysnchronous process in lost focus of the textbox is complete. i want to do this as i use the result from lostfocus in button click event.

Please let mt know if there is a way to make the lost focus wait till it completes the asynchronous call.



codebehind set focus textbox field in ajaxtoolkit : Tab


Hi all ,

I am stuck in the set focus field in field in ajaxtoolkit : Tab  at codebehind when button click.

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

    If StringUtil.IsStringEmpty(Me.ddlSex.SelectedValue) = True Then

       Page.ClientScript.RegisterStartupScript(Me.GetType, "ErrMsg", 
            JScriptUtil.ErrorMsg("Jantina (Sex): "

    End if

   End Sub

How to prevent Loss of Focus if there is Validation error on a textBox?

Hi i have a TextBox displayed as a TreeViewItem and when the user enters text and Tabs away or clicks somewhere else i want the control to retain focus if there is any validation error.Is there anyway i can do that? I am adding the ValidationRule to the TextBox created dynamically in code..I do see the default redborder when there is a validation error.I just want to force the user to correct the error and not go anywhere else in the app until its fixed..
Thanks in advance...

MaskedEditExtender, text removed if you lose focus and set focus back on textbox


I have a MaskedEditExtender with Mask="(999) 999-9999".

Now my problem is, if someone goes into the textbox and enters


Then they leave the textbox, and then see that they forgot to enter the area code, if they go back in there to enter the area code, it starts overwritting the other numbers instead of just adding to them. 

How to set focus to UserName textbox in Login Control ?



can you please tell how to focus cursor to UserName TextBox in Login control when page is loaded for the first time in browser ? 

setting focus to a textbox


using vb.net/asp.net 2005

after the user clicks on a button in the buttonClick event I am trying to set the focus at the end of the function simply as follows:


However the focus is instead going to another button.  The tabIndex property is not set on any controls on the page.  Has anyone experience this?  thanks


Set Focus on Textbox


    I have a composite control with Listbox and a Textbox. I am trying to achieve a functionality where in if I type something in the text box, the list box items gets filtered based on the text typed.

   I am able to get this working, however I am having issues in retaining the Keyboard focus in the Textbox.

   I am doing this functionality on the Key Up Event of the Textbox. If I type a text the event handler is getting triggered and performing the operation, but the focus goes from the Textbox

I am forcing the Focus by calling the Focus() function on the Textbox, but it doesn't seem to be working.

 SDK of Focus function says: "Even if an element is focusable and enabled, event handling within a specific tree, (such as for a composite control) might respond to the preview focus events by not allowing focus there, thus this method would return false."

How can I force the focus on the Textbox object.


How to empty a textbox in detailsview codebehind



I have a detailsview with three textboxes as itemtemplates. Each for holding a different date. To avoid the option of users entering invalid values the textboxes are disabled and the user can use a calender control to fill the dates. Because the textboxes are disabled I added a linkbutton to empty a date, if the user decides to clear it.


<asp:detailsview id="detailsview1" runat="server" height="50px" width="550px" CellPadding="2" 
                         datakeynames="ZavPogodbaID" datasourceid="SqlDataSource1" 
                         fieldheaderstyle-width="115px" autogeneraterows="false" DefaultMode="Insert" 
            <FieldHeaderStyle Width="150px" />
                <asp:TemplateField HeaderText="Stranka:" ControlStyle-Width="400px" ControlStyle-Font-Bold="true" >
                        <asp:DropDownList ID="ddlStranka&q

How to determine which textbox has focus?



I am trying to set the color of a textbox that has focus to gray. How can I tell which textbox currently has the curser on it so when they click the change color button it will change the textbox that is focused. Something like this:

focusedtextbox.BackColor = Drawing.Color.LightGray



set focus textbox inside modalpopupextender


hi all.

i am working wit modal popup extender where i wan to set focus to a text box in popup.

can any 1 help me out with detail. plz 

Word Count of a textbox in a DetailsView



Has anyone any advice or resources that they could provide with regards having a word count of a mulitline textbox that is found within a DetailsView?  I have tried using JavaScipt and a this page: http://aspnet.4guysfromrolla.com/demos/printPage.aspx?path=/articles/103107-1.aspx - but I don't seem to be able to get it working within that DetailsView,



abour changing border of textbox when focus textbox


Hi.i try to do this: when mouse come over the textbox, border color will change. When the mouse leave over the textbox, border of text turn the old type. Also, when textbox is focused,  border of textbox color will change. my problem here is focus event. i did mouseover and mouseleave. but i can't do focus event. My codes is below:

$("#txtsearch").mouseover(function ()


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend