hi
i added modal popup handler into my application
the popup which enmrges out is a panel and inside the panel i added the label and correspondong to label there is one textbox(txtE1)
now the problem i m facing is tht i want to write the method related to the Onkey press event of the txtE1 in the modal popup handler and that method(Ensure Numeric) is not handling the evnt of the txtE1 in modal popup handler.
this method is written in javascript an i tried by so many ways to access the txtE1 but not successful.
can anybody help me..??????

like

i hav this panel for the modal popup handler. .
it is outside the panel of my original form panel

<Script language ="javascrit">
Ensurenumeric()
{


}

</Script>


<asp:Panel ID="Panel1" runat="server" Height="300px" style = "display : none" CssClass="modalPopup"

Width="400px" Visible="True" >

<table style="width: 100%;"> 

<tr>

<td class="style1">

&nbsp;</td>

<td class="style2">

<asp:Label ID="lblE1" runat="server" Text="abc"></asp:Label><br>

</td>

<td>

<asp:TextBox ID="txtE1" runat="server" width="100px" Text="0.00" 

OnKeyPress="EnsureNumeric()" AutoPostBack="True"></asp:TextBox>

</td>

<td class="style1">

&nbsp;</td>

</tr>






</table>


</asp:Panel>








<cc1:ModalPopupExtender ID="Button1_ModalPopupExtender" runat="server" 

TargetControlID="lblEventTotal1" PopupControlID="Panel1"


CancelControlID="cancel" OkControlID="OKButton" BackgroundCssClass="modalBackground" >





</cc1:ModalPopupExtender>

Dani AI

Generated

Two separate issues show up in ’s posts: the client-side numeric handler inside the ModalPopup is never invoked, and the ModalPopup’s OK control does not fire a server-side Click. Both are common and usually come down to simple wiring problems (a broken script, ASP.NET client-id renaming, or a control that doesn’t actually post back).

The numeric-key problem

  • The script block in the sample is malformed (the tag/name is misspelled), so the function never gets defined and any inline handler will fail. Use a proper script tag and make the function return true/false, then attach it with onkeypress="return EnsureNumeric(event,this);" (or add it from code-behind with Attributes.Add("onkeypress", "...")). If client-side code looks up the textbox by id, use the rendered id (<%= txtE1.ClientID %>) because ASP.NET changes control ids. For pages using UpdatePanel, register client scripts with ScriptManager so they survive partial postbacks.

Example (corrected pattern):

<script type="text/javascript">
function EnsureNumeric(e, el) {
  e = e || window.event;
  var code = e.which || e.keyCode;
  if (code > 31 && (code < 48 || code > 57)) {
    if (e.preventDefault) e.preventDefault();
    e.returnValue = false;
    return false;
  }
  return true;
}
</script>

<!-- attach: onkeypress="return EnsureNumeric(event,this);" -->

The OK button not firing

  • OkControlID must point to a control that actually posts back. Use an asp:Button or another server control with runat="server" and an OnClick handler. If the modal or button is inside an UpdatePanel, add an AsyncPostBackTrigger for that button. Also check that no client-side OnClientClick returns false (which would cancel postback), and that the popup panel and controls are inside the page’s form runat="server".

Debug checklist

  • Open browser dev tools and look for JS errors. Verify the function name is defined in page source. Inspect the rendered id for txtE1 and ensure event attributes are attached. Add a temporary alert() in the handler to confirm it runs before adding validation logic. These checks resolve the vast majority of modal-popup client/server wiring issues.

hi,

i created an modal pop up extender on the particula label field.when label field is clicked , then popup opens ant it is having some texboxes.i want to store the values in the texboxes and then on clicking the okbuton of modalpopup handler,an event is fires that evaluates the values stored in textboxes and display it on the label.

the problem i am facing is that on clicking the okbutton ,event is not getting fired.

so hw shud i make it possible?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.