Solved

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

Posted on 2006-11-17
4
516 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
4 Comments
 
LVL 9

Expert Comment

by:kraffay
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now