?
Solved

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

Posted on 2006-11-17
4
Medium Priority
?
530 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 1800 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

765 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