I am new to ASP.NET and C# and have one doubt.
I have one link button in master page and I have one modalpopupextender in my content page.
I need When I click that button the modal popup window will open in the content page..
Can anyone help, it's very useful for me?
Thank you
Javascript and markup on the master page:
function showClientPopUp() {
var extender = $get("popupExtenderBehaviorID");
if (extender !== null) {
extender.show();
}
}
<asp:LinkButton runat="server" OnClientClick="showClientPopUp(); return false;" Text="Show PopUp"/>
Related
I am a desktop client developer. I now got to continue this project is ASP.NET with AJAX, so I am learning web development the hard way.
I need to get a list of all check boxes and their states from repeater control on Summary.aspx when user clicks button CmdSave on ChoicePage.aspx.
Can I subscribe to event CmdSave_Click() in Summary.aspx or is there some way to approach Summary.aspx's repeater control from ChoicePage.aspx?
(MSDN talks about passing values from page to page in this article but this doesn't help me)
Here is the problem:
Page ChoicePage.aspx is included in Master AppMaster.master page. ChoicePage has Content tag which includes CmdSave and it's event handler CmdSave_Click() and it also includes iframe tag for displaying another page, Summary.aspx
On Summary.aspx I have repeater control which is bound to DataSource and relevant fields are of type bool represented by column of editable check boxes. Clicking these checkboxes mustn't cause Summary.aspx to refresh so I am not looking to handle (server-side) CheckedChanged event.
I am not sure if any code example would help here since this is more a concept question
function SetFrameStatus() {
var v = hdCommand.value.toString().toLowerCase();
hdCommand.value = "";
var frms = (GetFrameAll("FrameSummary"));
if (frms)
{ }
else return;
FrameSummary = frms[0];
DivSummary = FrameSummary.parentNode;
var FrameWindow = frms[1];
var FrameDocument = frms[2];
if (v == "showsummary") {
FrameWindow.location.replace(SummaryPageName);
}
}
<asp:Content ID="ContentSummary" ContentPlaceHolderID="NoUpdateDiv" runat="server">
<div id="DivMenu" class="Flat" style="overflow:visible; display:none;position:absolute;">
<input type="button" id="CmdSave" value="Save" onclick="CmdSave_Click()" />
</div>
<div id="DivSummary" style="position:absolute;margin:0px;padding:0px;display:none">
<iframe title="Loading" id="FrameSummary" marginheight="0px" marginwidth="0px" scrolling="auto"
style="padding:0px; margin:0px;width:auto;" src="loading.htm?Redirect=Summary.aspx" frameborder="0"
onload="FrameSummary_Load()"
></iframe>
</div>
In the end this is what solved my problem:
On ChoicePage.aspx in CmdSave_Click() function I called another function on Summary.aspx.
This other function did __dopostback("Repeater", "") and on Render event in my code behind I iterate through a Repeater.
I am leaving this question unanswered because I am sure there is a better way to do this.
Hi,
I want to hide first calendar when a second is open or when the calendar field lost focus. The issue is that if the user doesn't select any date from calendar and go to other control in page the calendar doesn't hide, only when user select any date from calendar the popup hides. This capture show the problem.
I see that in ajaxtoolkit calendarextender sample page the calendar control works fine, when out from one to another calendar prior popup hides but I don't find the sample code of this page. I think this page manage in javascript the event when the focus is lost, but I had found any sample code or project ...
Thank you in advance!
As Yuri mentions, using an ImageButton fixes this... or...
You need to handle the onmouseout event. You can do it this way:
http://forums.asp.net/p/1182269/4708411.aspx/1?Re+Calendarextender+and+Lose+Focus+Or+Mouse+Out
Or you could add some javascript (via jQuery) and inject an onmouseout event:
Adding extra functions to an image's onmouseout attribute
This is also shown in the forums.asp.net link, but basically, on the onmouseout event you can just set the visibility of the calendar extender to hidden or none.
As an option in addition to solutions provided by dash, you may use following decision if you don't want to use ImageButton instead of Image for PopupButton: set OnClientShowing properties on extenders to "hideAnotherOpenedPoups" and add onto a page script below.
// Array of BehaviorIds of each extender for those you use Image as PopupButton
var behaviorIds = ["CalendarExtender1", "CalendarExtender2"];
function hideAnotherOpenedPoups(sender) {
for (var index = 0; index < behaviorIds.length; index++) {
if (behaviorIds[index] !== sender.get_id()) {
var extender = $find(behaviorIds[index]);
if (extender.get_isOpen()) {
extender.hide.call(extender);
}
}
}
}
Try the following line of code to show the calendar on both Textbox and Image click.
<asp:TextBox runat="server" onclick="showCalendar();" onfocusout="showCalendar();" ID="txtDate" />
<asp:ImageButton runat="Server" ID="imgPopup" AlternateText="Click to show calendar" />
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtDate" CssClass="MyCalendar" Format="MMMM d, yyyy" PopupButtonID="imgPopup" />
and add a javascript function like this
<script type="text/javascript">
function showCalendar() {
$( "#<%=imgPopup.ClientID %>" ).trigger( "click" ); //I've used .ClientID here just in case your page is inherited from a Master page
}
</script>
That should display the calendar when you click on the Textbox, and the calendar will be hidden once you click anywhere else on the form
i have a form on a particular ASPX page that has custom js validation. Also on this form is a navigation menu in the header.
The navigation menu items are built programatically and are initiated by __doPostBack calls which obviously submits the form.
The problem i am having is that the form itself has code something like the following
onsubmit='return validateForm()'
and if the form has not been filled out then the form cant submit. This in itself is not a problem unless a user goes to the form but decides to navigate away.
When this happens the validateForm function fails.
Does anyone have a workaround for this issue?
NB: On my nav links i have already set CausesValidation="False"
This is the markup:
<div id="divNavigate" class="absolute_topleft">
<asp:LinkButton ID="linkGoHome" runat="server" OnClick="linkGoHome_Click" CausesValidation="false" CssClass="xxx">text.</asp:LinkButton>
</div>
This is the handler:
protected void linkGoHome_Click(object sender, EventArgs e)
{
Response.Redirect("xxxxx");
}
This is the validation function:
function validateTextField(field) {
var fieldElement = document.getElementById(field);
var validated = false;
if (fieldElement.value.length > 0) {
validated = true;
}
return validated;
}
And this is how its called:
<form id="formLogin" runat="server" onsubmit="return validateTextField(field1)">
Are your navigation links proper asp.net server controls? If they are setting CausesValidation="False" should prevent them from causing validation. Can you post the code where you are dynamically adding them to the page, the most liekly explanation is the the CausesValidation property is not being set corectly.
I am using an update panel for a form that when continue button is clicked returns to the same page but makes visible different fields to be filled in. One of the fields is some credit card data and is part of a user control. The user control has a "Pay Now" button. So, inside the page there is a user control containing fields that you fill in and then click "Pay Now". After hitting this button, if there's a validation error, error shows at the top of the page but the page doesn't move to top of page. I would like to know how after the user clicks on the user control button that is on a page that is wrapped in update panel can I scroll to the top of the page.(javascript not jquery would be preferable in this instance)
Code samples:
<ajax:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ImageButton ID="ContinueButton" runat="server" AlternateText="Continue" SkinID="Continue" EnableViewState="false" OnClick="ContinueButton_Click" ValidationGroup="group1" />
</ContentTemplate>
</ajax:UpdatePanel>
In Code behind a user control is instantiated.
ASP.CreditCardStuff cc = new ASP.CreditCardStuff();
cc.ValidationGroup = "group1";
phForms.Controls.Add(cc);
This is the user control that contains the "Pay Now" button
How about providing a validation error indicator next to the button as well as at the top of the page? This way the page would remain scrolled to the same point (nicer for the user), rather than jumping to the top, purely to make the error indicator at the top of the page visible (not so nice).
You could handle the end_request event:
function pageLoad(sender, args) {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function (sender, args) {
if (args.get_error() == null) {
// do the scrolling here
}
});
}
I have an ASP.NET application where there's a few ASP.NET buttons and several plain HTML buttons. Anytime there's a textbox where a user hits enter, the ASP.NET button tries to submit the form.
I know I can change the defaultButton, but I don't want there to be any default button. I just want it so when the user presses enter it doesn't do anything.
I've tried setting defaultButton to blank, but that doesn't seem to work. How do I prevent the form from being submitted by the ASP.NET button when enter is pressed?
You can set the button's UseSubmitBehavior = false
btnCategory.UseSubmitBehavior = false;
Here is what I used to fix this problem.
<form runat="server" defaultbutton="DoNothing">
<asp:Button ID="DoNothing" runat="server" Enabled="false" style="display: none;" />
I also had this problem with an ImageButton on my MasterPage (the Logout button) being set as the default button (so whenever someone pressed Enter, it would log them out). I solved it by using the following line in the Page_Load event on every child page, which is a bit of a work-around, but it works:
Form.DefaultButton = cmdSubmit.UniqueID;
Hope this helps someone else.
<asp:TextBox ID="TXT_Quality" runat="server" Width="257px"
onkeypress="return key_Pressed(event, this);">
</asp:TextBox>
function key_Pressed(e, textarea)
{
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13)
{
return false;
}
return true;
}