Solved

Problems with Attributes.Add("onclick",....  and MyTextBox_TextChanged

Posted on 2006-11-17
4
527 Views
Last Modified: 2012-06-27
Hello,

Controls on webpage:
 - Datagrid
 - TextBox

Datagrid has Delete button:

<asp:TemplateColumn HeaderText="Borrar">
      <HeaderStyle Width="10%"></HeaderStyle>
      <ItemStyle HorizontalAlign="Center"></ItemStyle>
      <ItemTemplate>
            <asp:ImageButton id="btnDelete" runat="server" CommandName="Delete"></asp:ImageButton>
      </ItemTemplate>
</asp:TemplateColumn>

At function MyDatagrid_ItemCreated , I add attributes to that Delete button. So, when the user click on Delete button, then it's showed a confirmation message before to proceed to delete the record.

Private Sub MyDatagrid_ItemCreated(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles MyDatagrid.ItemCreated
        If (e.Item.ItemIndex > -1) Then
            Dim mydeletebutton As TableCell
            mydeletebutton = e.Item.Cells(0)
            mydeletebutton.Attributes.Add("onclick", "return alert('Are you sure you will delete record...?');")
        End If
End Sub

Now my problem is that the user has to write on the TextBox. When user focus on the TextBox and then press ENTER, then it is showed windows message: 'Are you sure you will delete record...?'.
I tried to put hide buttons on the webpage, but no success.
Allways when the user hit ENTER on the TextBox, the message appears on screen.

This function is never raised:

    Private Sub MyTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyTextBox.TextChanged
         ' Some code goes here ....
    End Sub

How could I solve that?
Thank you!
0
Comment
Question by:miyahira
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 9

Expert Comment

by:kraffay
ID: 17967139
Check you tab index.  You may be able to get the focus to go to a control after the textbox
0
 
LVL 10

Expert Comment

by:ibost
ID: 17967201
Not sure where the problem is based on the code you've provided.

Here is a very good tutorial on adding client-side confirmation box for deleting datagrid items.  Note he uses the ItemDataBound instead of ItemCreated:

http://aspnet.4guysfromrolla.com/articles/090402-1.aspx

Hope that helps
-Ian
0
 
LVL 1

Author Comment

by:miyahira
ID: 17967848
Funny. Only solution I found: I had to put a button with minimal dimensions above the datagrid, so when the user press Enter at the TextBox, then Minimal_Dimesions_Button will fire nothing
0
 
LVL 4

Accepted Solution

by:
Xeavn earned 450 total points
ID: 17968213
This is how I solved the solution. I made a javascript function called t4e and then on the text box I just set OnKeyDown = to that function.
This causes it to tab instead of acting like an enter key.

<asp:TextBox id="StartLabNumber"
      MaxLength="23"
      Style="width:13em;"
      OnKeyDown="t4e();"
      TabIndex="1"
      RunAt="Server" />


<script type="text/javascript">
<!--
function t4e(){
if(event.keyCode==13){
event.keyCode=9;
}
}
-->
</script>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question