?
Solved

on key press in code behind

Posted on 2013-01-27
3
Medium Priority
?
1,833 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

719 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