Issue with ModalPopup in asp.net/C# - c#

I have used modalpopup control in my web application and after open it when i click on ok button i have make call to WCF function to deal with some functional requirement.
Currently the behavior like , when i will click on OK button ModalPopup remained open until my WCF operation is completed and when it will completed it will be closed because i write down logic to hide in code behind file and my code as per below
<asp:Panel ID="PanelCheck" runat="server" CssClass="modalPopup" SkinID="Custom">
*Panel content here..*
<asp:Button ID="OkButton" runat="server" Text="Create" OnClientClick="return
ValidateSeconds();" OnClick="OkButton_Click" />
</asp:Panel>
<cc1:modalpopupextender id="MPE" runat="server" targetcontrolid="lnkTemp"
popupcontrolid="PanelCheck" backgroundcssclass="modalBackground" />
code behind
protected void OkButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
try
{
MPE.Hide();
*Logic to deal with WCF call..*
}
}
catch (Exception ex)
{
throw ex;
}
timerInstance.Enabled = true;
}
}
Now what i require is i need to close modalpopup first and then asynchronously it should make WCF call I could not find any ways to do that, please anyone help me if this question make any sense.
Thanks in Advance

I believe you can hide ModalPopupExtender on the client side right after clicking the “Create” button:
<asp:Button ... OnClientClick="return ValidateSeconds();" />
function ValidateSeconds() {
//your code
$find('MPE').hide();
//your code
}
See Also:
How to Show / Hide a ModalPopupExtender using Javascript

Related

asp button on click event does not enter the onclick function c#

I know there already exist a thread for the same question but it didn't help me fix it (I tried what they suggested) anyways here is the html side of the button, is there anything I'm missing:
<asp:Button ID="btnadd" runat="server" Text="add" OnClick="btnadd_Click" CausesValidation="False"/>
And this is the c# side:
protected void btnadd_Click(object sender, EventArgs e)
{
//do something
}
EDIT: solution, i had the button inside a form causing it not to work, removed the form and it worked

Displaying a div on a button click in asp.net

I want to display a particular div on the click of a button
My asp code is as follows
<asp:Button ID="Button1" class="btn" runat="server" OnClick="Submit" />
<div runat="server" id="signup" Visible="false">Some Content </div>
Now in the CodeBehind i have written the following code
protected void Submit(object sender, EventArgs e)
{
Button1.Visible = false;
signup.Visible = true;
}
But every time i get the error as
the name signup does't exist in the current context
i am not able to figure out the problem in the code..
You probably have wrong html for the div, you can also use style="visible:none" instead of Visible="false"
Change
visible:"false"
To
Visible="false"
This has to be done through JavaScript, I believe in the onClientClick attribute of the button. I'm currently searching for the code to jog my own

how to prevent web page refreshing

I have a "CaptchaControl" in a webusercontrol, when i click refresh link for the captcha code, the page refresh too. how can i prevent it?
<cc:CaptchaControl ID="captcha" CssClass="toppading" runat="server" CharCount="5" ImageUrl="~/images/CapchaImage.jpg" />
<asp:LinkButton CssClass="leftpading" id="btnReset" runat="server" Text="Refresh" resourcekey="lblrefresh" OnClick="btnReset_Click" ></asp:LinkButton>
protected void btnReset_Click(object sender, System.EventArgs e)
{
captcha.Refresh();
}
i've heard something about ajax, but i'm green in ajax.
Ajax is the best solution for this problem.ajax will send data to your server with out making a post back in your browser.
Just add an ajax update-panel in your form(you can find this in your Toolbox under the tab Ajax extensions) and put your user-control inside it.And don't forget to add a script-manager in the beginning of your form.

Button need to be click twice to fire an event

I have a simple ASP.NET Button inside of iFrame, for strange reason i have to click it twice in order to fire an event.
<asp:Button ID="btnSaveComment" runat="server" Text="Add Comment"
CssClass="button"
OnClick="btnSaveComment_Click"
ValidationGroup="add" />
protected void btnSaveComment_Click(object sender, EventArgs e)
{
AddComment();
}
I suspect that when you initially click an area above the button you're giving focus to the iframe (that is to say, the page within it), and on the second click the mouse can interact with the button.
On the other hand, if the page seems to be posting back but not actually doing anything until the second click, then it might well be related to the page lifecycle, as suggested in an answer comments by #AndroidHustle.
Edit:
To test the theory of whether or not the frame is focused, try giving it focus via script. Something like the following might help:
<script type="text/javascript">
document.getElementById("iFrameId").focus();
</script>
I had the same problem. Here is how I solved it:
$("#MainContent_Button1").hover(function (event) {
$("#MainContent_Button1").click()
});
Now it only takes 1 click, and the button functions like it's supposed to.
<asp:Button ID="Button1" runat="server" Text="Save Payment Plan" OnClick="Button1_Click" />

How close Html window when click asp.net button?

I have asp.net button "OK" in html popup window. I after my logic done how close that popup window it self?
<asp:Button Id="btnOK" runat="server" AccessKey="<%$Resources:
wss,multipages_okbutton_accesskey%>" Width="70px" Text="<%$Resources:wss,
multipages_okbutton_text%>" OnClick="btnOK_Click" />
<asp:Button ID="btnOK" runat="server" OnClientClick="window.close(); return false;" Text="Close" />
All correct but there is another way if you want close the window in your code:
Suppose that the button ID is "ContineButton" and the click event handler name is "ContineButton_Click"
protected void ContineButton_Click(object sender, EventArgs e)
{
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
}
If there is a chance that your server side code may fail, and you need to keep the popup open to correct errors, the OnClientClick trick won't help. I do this with a PlaceHolder and a small script:
<asp:PlaceHolder id="close_script" runat="server">
<script>window.close();</script>
</asp:PlaceHolder>
Then, in the button handler, set the Visible property of the PlaceHolder to close the popup (or leave it open:
protected void btnOK_Click(Object sender, EventArgs e) {
bool success = processPage();
close_script.Visible = success;
}
That requires some javascript. Change your button markup to this:
<asp:Button Id="btnOK" runat="server" AccessKey="<%$Resources:
wss,multipages_okbutton_accesskey%>" Width="70px" Text="<%$Resources:wss,
multipages_okbutton_text%>" OnClick="btnOK_Click" OnClientClick="javascript:window.close(); return false;" />
There are other things to consider here - an accessible site will work without JavaScript including opening and closing a popup window. It will be dumbed down, but still function. Take a look at this article:
http://accessify.com/features/tutorials/the-perfect-popup/

Categories

Resources