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/
Related
Hi I want to open popup window in button click event without using j-query in asp.net C#.
This is simple task i am familiar with Asp.Net MVC. But i am not familiar in Asp.Net so only i am struggling for this simple task.
Please any one tell me how to open popup window by button click event without using jquery in asp.net C#.
My web form
SpecilalityMaster.Aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="specialitymaster.aspx.cs" Inherits="popupwindow.admin.specialitymaster" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<form id="frmPopupExample" runat="server">
<asp:Button ID="btnOpenPopupWindow"
runat="server"
Text="Open Popup Window" OnClick="btnOpenPopupWindow_Click"
/>
</form>
<div class="popup">
<asp:TextBox ID="_lname" runat="server"></asp:TextBox>
<asp:Button ID="Button1"
runat="server"
Text="save" OnClick="Button1_Click"
/>
</div>
</asp:Content>
specialitymaster.aspx.cs
public partial class specialitymaster : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOpenPopupWindow_Click(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
i just tried simply. i designed one button and one popup window.if i click open popup window in button click event i need to open popup window. i donno it is possible or not.i created button click event in CS page but i donno how to call that popup window name in button click event .
example
Desirable result: Please see image.
If I understand you correctly, you don't need a popup, you just trying to activate some div on your page. You will need to make this div server side
<div class="popup" runat="server" style="display:none" id="divPop">
<asp:TextBox ID="_lname" runat="server"></asp:TextBox>
<asp:Button ID="Button1"
runat="server"
Text="save" OnClick="Button1_Click"
/>
</div>
and then in your server side click
protected void btnOpenPopupWindow_Click(object sender, EventArgs e)
{
divPop.Attributes.Add("style", "display:block);
}
this will make your div visible
EDIT
better solution in your case would be using asp panel instead of div.
<asp:panel id="divPop" visible="false" runat="server">
<asp:TextBox ID="_lname" runat="server"></asp:TextBox>
<asp:Button ID="Button1"
runat="server"
Text="save" OnClick="Button1_Click"
/>
</asp:panel>
and then you will be able to manipulate visibility in your server side code very easy
protected void btnOpenPopupWindow_Click(object sender, EventArgs e)
{
divPop.Visible=true;
}
you are using server side control in your code.
<asp:Button ID="btnOpenPopupWindow"
runat="server"
Text="Open Popup Window" OnClick="btnOpenPopupWindow_Click"
/>
click of this button will trigger immediate post to the server and server (your ASP.NET application) will handle the event. The only way you will be able to open a popup from the server if you will register script to do this. Your CLick should look something like
protected void btnOpenPopupWindow_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(),
"yourWindowName",
String.Format("<script>window.open('{0}');</script>", yourURL));
}
Use this:
var DefineWindowSize= "location=yes,height=570,width=520,scrollbars=yes,status=yes";
var URL = "https://www.google.com";
var win = window.open(URL, "_blank", DefineWindowSize);
Create a function and add it inside the function.
im trying to make a user control to popup when a button is clicked! now i dont want to hide the user control and then show it when the button is clicked,
im NOT trying to do this:
test1.aspx
<uc1:PopUp ID="PopUp1" runat="server" Visible="false" />
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button1_Click" />
test1.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
if(PopUp1.Visible==false)
PopUp1.Visible = true;
else
PopUp1.Visible = false;
}
i want the page loads without it and if the button is clicked it fires! is it possible?
btw, im open to any other suggestion other than using user control
thank you in advance
i need to fire html buttom after the end of my asp.net c# code
<asp:Button ID="Button3" runat="server"
Text="Button" onclick="Button3_Click" />
<input id="Button2" type="button" value="button" data-type="error" class="growl-type2" runat="server" />
and cs code is
protected void Button3_Click(object sender, EventArgs e)
{
----
i need to fire button2( automatically) in this position
}
Button clicks are just handled events. To fire a button click you simply need to raise the correct event.
You'll need something like: Button2_Click(sender, e)
Alternatively, you can inject some Javascript into the page, which reacts directly to the click of button3 or is caused by the click of button3 and causes the click of button2 through something like: document.getElementById('Button2').click()
I have a user control that allows the user to add/edit a worker. When the user clicks the 'Add Worker' button the user control appears in a DevExpress Popup. All of the following button are in an update panel to prevent Postbacks.
When I edit a user (pencil) everything works fine. To edit a user I enter a last name, click search (magnifying glass) and then click edit (pencil). It's only when I load the page and click add the save/cancel buttons do not work.
I add the control in asp.net
<dx:PopupControlContentControl ID="PopupControlContentControl2" runat="server" SupportsDisabledAttribute="True">
<uc:WorkerAddEdit ID="wae" runat="server" OnOnWAECancelEvent="wae_OnWAECancelEvent" OnOnWAESaveEvent="wae_OnWAESaveEvent" />
</dx:PopupControlContentControl>
Here is the C# code behind the edit (the one that works correctly. The pencil)
protected void btnEditWorker_Click(object sender, EventArgs e)
{
SetupSessions();
wae.WorkerEdit = loadedWorker;
pucAddEditWorker.HeaderText = "Edit Worker";
pucAddEditWorker.ShowOnPageLoad = true;
}
Here is the C# code behind for the add (the round + that doesn't work)
protected void btnAddWorker_Click(object sender, EventArgs e)
{
wae.WorkerEdit = null;
pucAddEditWorker.HeaderText = "Add Worker";
pucAddEditWorker.ShowOnPageLoad = true;
}
Here is the asp.net section of the save and cancel button. This shows both onClick calls
<td><dx:ASPxButton ID="btnSave" runat="server" Text="Save" Theme="MetropolisBlue"
Width="50px" Height="20px" style="float:right;" onclick="btnSave_Click" /></td>
<td><dx:ASPxButton ID="btnCancel" runat="server" Text="Cancel"
Theme="MetropolisBlue" Width="50px" Height="20px" style="float:right;"
onclick="btnCancel_Click" /></td>
Here is the events in the code behind
protected void btnCancel_Click(object sender, EventArgs e)
{
//Do Work Here
}
protected void btnSave_Click(object sender, EventArgs e)
{
// Do Work Here
}
If I put a break point on either the save or cancel click event nothing ever happens. I've been googling for a while now with no luck.
Thanks in advance.
In Design mode of the form, have you tried clicking the control once, and check it on Properties (Events) window? Maybe the Click event does not have any method selected.
Select the btnSave_Click method in the Click label.
I figured out what the problem was. I am using a textbox from DevExpress. Further up in my code I had the textbox as follows:
<dx:ASPxTextBox ID="txtPhoneNumber" runat="server" Width="100px" Theme="MetropolisBlue" >
<MaskSettings Mask="(999) 000-0000" IncludeLiterals="None" />
<ValidationSettings Display="None">
</ValidationSettings>
</dx:ASPxTextBox>
Because I had the 0's in the mask it was trying to validate whatever was in the text box. Because I turned off the validation settings (ValidationSettings Display="None") I never saw the error but it was still validating. I made a change to this:
<dx:ASPxTextBox ID="txtPhoneNumber" runat="server" Width="100px" Theme="MetropolisBlue">
<MaskSettings Mask="(999) 999-9999" IncludeLiterals="None" />
<ValidationSettings Display="None">
</ValidationSettings>
</dx:ASPxTextBox>
and everything worked fine. I just started using DevExpress and it shows! Thanks to everyone for the help!
I did a lot of searching and cannot figure this out.
I have a ModalPopupExtender pop-up that I want to display when the user clicks a link DoSomething. The pop-up has a dropdown control that I then want to populate on the fly when the user asks to open the dialogue. This needs to happen server side via the code behind. Currently I am trying to do it via an OnClick event on the link but as soon as the link is tied to the ModalPopupExtender the link OnClick code is not executed.
Code snippet:
<asp:LinkButton ID="lnkDoSomething" runat="server" onClick="lnkDoSomething_Click">Do Something</asp:LinkButton>
<asp:ModalPopupExtender ID="mpelnklnkDoSomething" runat="server" BackgroundCssClass="modalBackground"
DropShadow="true" PopupControlID="lnkDoSomething"
PopupDragHandleControlID="pnlDragHandlerForlnkDoSomething"
TargetControlID="lnklnkDoSomething"></asp:ModalPopupExtender>
The problem is as soon as I set the ModalPopupExtender to the link the OnClick code does not execute. This obviously is by design but it doesn't make sense to me (naive) as if the user clicks the link the OnClick code should be executed.
Any ideas why this is not supported and what the correct solution is?
Attach the ModalPopupExtender to a dummy button and show the modal on the LinkButton's OnClick even from the code-behind:
Markup:
<asp:LinkButton ID="lnkDoSomething" runat="server" onClick="lnkDoSomething_Click">Do Something</asp:LinkButton>
<asp:Button id="dummyButton" runat="server" style="display:none;" />
<asp:ModalPopupExtender ID="mpelnklnkDoSomething" runat="server"
BackgroundCssClass="modalBackground" DropShadow="true" PopupControlID="controlToPopUpId"
PopupDragHandleControlID="pnlDragHandlerForlnkDoSomething"
TargetControlID="dummyButton"></asp:ModalPopupExtender>
Code-behind:
protected void lnkDoSomething_Click(Object sender, EventArgs e)
{
//do work
mpelnklnkDoSomething.Show();
}