Cannot run event handler in .cs file from ModalPopupExtender - c#

I want to create a simple Yes/No popup window. So I have added a ModalPopupExtender to the .aspx page.
The popup panel's markup is:
<asp:Button ID="btn_yes" runat="server" Text="Yes" onclick="btn_yes_Click" />
<br/>
<br/>
<asp:Button ID="btn_no" runat="server" Text="No" />
For some reason, I cannot get into the function btn_yes_Click, not sure why. Do I have to use Javascript?

I suspect that you are also setting the ModalPopupExtenders OkControlID property to "btn_yes".
As you can see in this related question this will cause the OnClick event not to fire.

There is a chance that the OKControlID Property on ModalPopupExtender tag is specified. Take a look at this topic: The Event Handler of the OK button inside a Modal PopUp is not executing

Related

Submit Event Not Firing on Control

I have a webpage with a control to handle all the comments so I don't have to copy the code from one page to another. When I click the button, the code to handle the submit is not happening. I want the page to have no .axd references.
This is my form statement on the .aspx page
<form id="formAlpha" method="post" runat="server" action="">
<Comm:Comm ID="comments" runat="server" />
</form>
The processing for saving the comments is in the control.aspx
In the code of the webpage, I set the action to be
formAlpha.Action = Request.RawUrl;
This is my submit button in the control.
<asp:button ID="cmdSubmit" CausesValidation="false" UseSubmitBehavior="true" text="Submit" runat="server" OnClick="cmdSubmit_Click" OnClientClick="return ValidateSubmission();" />
The JS code executes correctly, it displays an alert box and then returns true. THe page reloads but the click event doesn't work. The load event fires up again and the IsPostBack is false. Its not submitting but reloading.
I'm using WebForms C#, not MVC
Just an idea taken from the official MSDN page, remove the "return" (and maybe the semicolon too) keyword from the onClientClick declaration:
OnClientClick="ValidateSubmission()"

ASP: Html Form action calls automatically on textbox OnTextChanged

I have defined form action in my asp page and with in form, I have defined the Textbox OnTextChanged. but when I type any thing on Textbox and click on tap to move next.. automatically instead of calling OnTextChanged ..my form action calls..
my code is below
<form id="WebToLead" action="https://url" method="POST" runat="server">
<asp:TextBox id="a" name="a" maxlength="10" runat="server" OnTextChanged="a_TextChanged" AutoPostBack="true" />
// some more textbox
<asp:Button ID="Button2" Text="Click" width="50px" runat="server" OnClick="Button2_Click" />
</form>
Means it action should be triggered on button2_click but it does when i type anything on aand tap to other fields
Ensure you have viewstate enabled for this to work, otherwise Asp.Net has no way of knowing whether the control's value has changed.
AutoPostBack is enabled thats why it is posting the form back to server. Remove it or disable it. It should work after that.

How to use a page after opening another page with target=_blank?

I can open another window to display some stuff, but then I cannot use the buttons on the original page anymore. Why is this and how to fix it? This is my code:
<asp:Button ID="Button_ViewSimpleRequest" Text="Simple Request" runat="server" OnClientClick="window.document.forms[0].target='_blank'" PostBackUrl="~/xyz.aspx" />
<asp:Button ID="Button_Self" Text="Self" runat="server" OnClientClick="window.document.forms[0].target='_self'" />
After clicking the first button, the second button also redirects to xyz.aspx. How do I make the second button behave like a normal button on the original page?
I tried: <asp:Button ID="Button_ViewSimpleRequest" Text="Simple Request" runat="server" OnClientClick="window.open('xyz.aspx', 'name')" /> which is simple, and seems to work.
I found my solution by studying How to launch another aspx web page upon button click.

modalpopupextender set to multiple target control IDs?

Is it possible to tie one modalpopupextender to multiple target controls (multiple buttons)?
Thanks
Behrouz
Good Answer, I will just add to it:
For me I had to change onclick to OnClientClick:
<asp:Button ID="btn_contact2" runat="server"
OnClientClick="javascript:$find('popup1').show();return false;"
Text="Possibilites" />
You need to add a BehaviorID to the modalpopup:
BehaviorID="popup1"
I don't think you can specify multiple targets for the ModalPopupExtender. But you can call it from other controls via JavaScript by adding something like this to their onclick handler:
<act:ModalPopupExtender id="mpePopup" runat="server" BehaviorID="bePopup" ... />
<asp:Button id="btnOther" runat="server" Text="Open Dialog" OnClientClick="$find('bePopup').show();return false;" />
The key is to provide a value for "BehaviorID" in the extender control. This enables client-side access via the "$find(behaviorID)" method, from which you can ".show()" or ".hide()" the modal popup.

ScriptManager.RegisterClientScript in a UserControl within a FormView inside an Async Panel

I'm having an annoying problem registering a javascript event from inside a user control within a formview in an Async panel. I go to my formview, and press a button to switch into insert mode. This doesn't do a full page postback. Within insert mode, my user control's page_load event should then register a javascript event using ScriptManager.RegisterStartupScript:
ScriptManager.RegisterStartupScript(base.Page, this.GetType(), ("dialogJavascript" + this.ID), "alert(\"Registered\");", true);
However when I look at my HTML source, the event isn't there. Hence the alert box is never shown. This is the setup of my actual aspx file:
<igmisc:WebAsyncRefreshPanel ID="WebAsyncRefreshPanel1" runat="server">
<asp:FormView ID="FormView1" runat="server" DataSourceID="odsCurrentIncident">
<EditItemTemplate>
<uc1:SearchSEDUsers ID="SearchSEDUsers1" runat="server" />
</EditItemTemplate>
<ItemTemplate>
Hello
<asp:Button ID="Button1" runat="server" CommandName="Edit" Text="Button" />
</ItemTemplate>
</asp:FormView>
</igmisc:WebAsyncRefreshPanel>
Does anyone have any idea what I might be missing here?
Have you tried using RegisterClientSideScript? You can always check the key for the script with IsClientSideScriptRegistered to ensure you don't register it multiple times.
I'm assuming the async panel is doing a partial page past back which doesn't trigger the mechansim to regenerate the startup scripts. Perhaps someone with a better understanding of the ASP.Net Page Life Cycle and the CLR can fill in those blanks.
For me that works fine. resizeChartMid() is a function name.
ScriptManager.RegisterStartupScript(this, typeof(string), "getchart48", "resizeChartMid();", true);
Try this, i got the same issue
ScriptManager.RegisterClientScriptBlock(MyBase.Page, Me.[GetType](),
("dialogJavascript" + this.ID), "alert(\"Registered\");", True)
This worked for me!

Categories