Solved

on key press in code behind

Posted on 2013-01-27
3
1,756 Views
Last Modified: 2013-03-25
Gridview edit I want to check and make sure a valid value is entered.


protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
           
           
            GridView gv = (GridView)sender;
            GridView1.Rows[e.NewEditIndex].Attributes.Add("onkeyup", "keyPress(this)");
                        gv.EditIndex = e.NewEditIndex;
            gv.DataBind();
        }
<script type="text/javascript">
    function keyPress(e)
    {


        alert('hi key pressed');

        


    }
</script>

Open in new window

0
Comment
Question by:mikensu12
[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
3 Comments
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 38823696
i think you should bind this event on row data bound instead of rowediting

example:
    Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then

 Dim btnPreview As Button = e.Row.Cells(10).Controls(1)
'here we search for the control


            If Not btnPreview Is Nothing Then
                btnPreview.Attributes.Add("OnClick", "javascript:showlnk(" & btnPreview.CommandArgument & ");")
            

            End If



 End If
    End Sub




showlnk is a javascript function

Open in new window

0
 
LVL 20

Expert Comment

by:informaniac
ID: 38824803
You want to check the value of a TextBox in the row?

protected void gvTextBox_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex == gvTextBox.EditIndex)
            {
                TextBox txt1 = e.Row.FindControl("txt1") as TextBox;
                 txt1.Attributes.Add("onkeyup", "keyPress(this)");
            }
        }

Open in new window

0
 
LVL 10

Accepted Solution

by:
Monica P earned 500 total points
ID: 38825681
u make keypress event in edit mode of Gridview text box like this also

<EditItemTemplate>
                        <asp:TextBox ID="gvdtxtHR" onkeypress= "javascript:return KeyPress(event, this,3,2);" runat="server" Text='<%# Bind("hotel_rate") %>' Width="40px" ></asp:TextBox>                      
</EditItemTemplate>

Refer : http://forums.asp.net/t/1235027.aspx

Javascript function

function KeyPress(event, ctlName,explen,decLen)

    {
   
    var cntNbr=document.getElementById(ctlName.id).value;
      
    } 

Open in new window

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

710 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