[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

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

Technology Partners: 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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

872 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