I am new at AJAX When i enter the web page it gives an error which is
``(c:\Users\Acer\Desktop\RSS_proje\RSS_proje\WebApplication2-5.2\ShareRss.aspx
var lblMsg = $get('<%=lblMessage.ClientID%>');){"Control 'ScriptManager1' of type 'ScriptManager' must be placed inside a form tag with runat=server."}
javascript side
HTML code[code:html]<asp:ScriptManager ID="ScriptManager1" runat="server">
function onCancel() {
var lblMsg = $get('<%=lblMessage.ClientID%>');
lblMsg.innerHTML = "You clicked the <b>Cancel</b> button of AJAX confirm.";
}
also, button side
<asp:Button ID="Button1" runat="server" Text="Share RSS" BackColor="#FF6600"
BorderColor="#FF9933" BorderStyle="Solid" Font-Bold="True" ForeColor="White"
Width="78px" onclick="Button1_Click" />
<ajaxToolkit:ConfirmButtonExtender ID="cbe" runat="server"
TargetControlID="Button1"
ConfirmText="Are you sure you want to share this?"
OnClientCancel="CancelClick" />
<asp:Label ID="lblMessage" runat="server"></asp:Label><br />
C# SIDE
protected void Button1_Click(object sender, EventArgs e)
{
lblMessage.Text = "You clicked the <b>OK</b> button of AJAX confirm";
}
If the ScriptManager tag is formatted exactly as you have it posted then make sure you're providing the appropriate closing tag for it. If you already are could you post a bit more of your markup so we can gat a better picture of how your Dom is structured
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.
Here is my code:
<form id="form1" runat="server">
<asp:GridView ID="gridv" AutoGenerateColumns="true" EnableViewState="true" runat="server" >
<Columns>
<asp:HyperLinkField runat="server" HeaderText="GetStudentInfo" SortExpression="GetStudentInfo" DataTextField="StudentName" NavigateUrl="StudentManagement2.aspx" />
</Columns>
</asp:GridView>
<asp:Button runat="server" Text="Click" OnClick="ClickPostback" />
</form>
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
gridv.DataSource = GetStudent();
gridv.DataBind();
}
When i click on the hyperlink on GridView - Postback is always false:
However when i click the Button Postback variable is True:
A post back occurs when a form gets submitted back to the server.
Hyperlinks are used for navigation, not form submission. So by default they redirect the user to a new page and do not post any information back to the server, which is why the post back is showing as false.
In your example the hyperlink has a NavigateUrl property which is where you are telling the application to "go to this page". It's not sending any information to the server for processing.
Buttons however where designed to post information back to the server, which is why it is showing true.
I tried using this example: http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/modalpopup/modalpopup.aspx
<ajaxToolkit:ModalPopupExtender ID="MPE" runat="server"
TargetControlID="LinkButton1"
</ajaxToolkit:ModalPopupExtender>
And try using
MPE.Show();
on the C# side but I keep getting an error message:
"The name 'MPE' does not exist in the current context" I really don't know why the C# side can't see the asp side.
I mean the popup doesn't have to use ajax but that's what I was currently trying at the moment.
The modal popup extender needs a control to extend:
<!-- modal popup target - hidden -->
<asp:Button ID="btnModalTarget" runat="server" style="display:none;" />
<cc1:ModalPopupExtender ID="PopupExtender1" runat="server"
BehaviorID="ModalPopupBehavior1"
TargetControlID="btnModalTarget"
PopupControlID="Panel1">
</cc1:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server">
<!-- popup contents -->
</asp:Panel>
<asp:LinkButton ID="Button1" runat="server" Text="Open" OnClick="Button1_Click" />
Code-behind:
protected void Button1_Click(object sender, EventArgs e)
{
PopupExtender1.Show();
}
I am trying to bypass the ConfirmButtonExtender depending on the value of another field in the page.
Basically, when a user click on my "Cancel" button, I normally display a modalpopup using the confirmbuttonextender and the modalpopupextender to display a dialog box confirming that they wish to cancel any changes they have made and return to the prior screen. If they click Yes, the button's onclick event fires which calls some code in the codebehind and redirects the user to another page. If they click no, it just returns to the same page, with no changes.
However, in some situations, I know that my user is unable to perform any edits (they aren't allowed to) and for those users, I don't want to display the "Are you sure you want to leave you will loose any changes" dialog box.
I've set a hidden checkbox field named "cbAllowEdit" to indicate whether the user is allowed to edit the fields or not.
I was trying to use the technique found at link text to get this working but it just doesn't even seem to be firing the button's onclientclick event at all.
Here is my code.
ASPX & Javascript
<asp:CheckBox ID="cbAllowEdit" runat="server" Checked="true" />
<asp:Button ID="btnCancel" runat="server" CausesValidation="false"
OnClick="btnCancel_Click" Text="Cancel" OnClientClick="disableSubmit();return false;" />
<ajaxToolKit:ConfirmButtonExtender ID="ConfirmButtonExtenderbtnCancel"
runat="server" DisplayModalPopupID="ModalPopupExtenderbtnCancel"
TargetControlID="btnCancel" BehaviorID="ConfirmButtonExtenderbtnCancel" />
<ajaxToolKit:ModalPopupExtender ID="ModalPopupExtenderbtnCancel" runat="server"
BackgroundCssClass="modalBackground" CancelControlID="btnCancelCancel"
OkControlID="btnConfirmCancel" PopupControlID="ConfirmCancelPanel"
TargetControlID="btnCancel" />
<asp:Panel ID="ConfirmCancelPanel" runat="server" CssClass="modalWindow"
Height="200" Width="450">
<p class="confirmMessage">
Are you sure you want to navigate away from this record?
</p>
<div align="center">
<p class="feedbackError">If you have made any changes to the record since the last time
you saved, they will be lost.</p>
<asp:Button ID="btnConfirmCancel" runat="server" Text="Yes" Width="75" />
<asp:Button ID="btnCancelCancel" runat="server" Text="No" Width="75" />
</div>
</asp:Panel>
<script type="text/javascript">
function disableSubmit() {
if (document.getElementById('<%= cbAllowEdit.ClientID %>').checked) {
return checkSubmit();
}
else {
return true;
}
}
function checkSubmit() {
var confirmButton = $find('ConfirmButtonExtenderbtnCancel');
confirmButton._displayConfirmDialog();
}
</script>
Code behind:
/// <summary>
/// Runs when the btnCancel button is clicked.
/// </summary>
protected void btnCancel_Click(object sender, EventArgs e)
{
Page.Response.Redirect("~/Searches/LookupCode/Default.aspx");
}
any ideas on what I am doing wrong?
As Chris said, you don't have to have a ConfirmButtonExtender and ModalPopupExtender (although this looks like a way round the fact that the JavaScript confirm() function is limited to OK and Cancel buttons in its' dialog - noted as a technique for the future :-) )
If you know in your code-behind that the user isn't going to be doing any editing (as evidenced by your cbAllowEdit control), then you should be able to just disable the ConfirmButtonExtender:
ConfirmButtonExtenderbtnCancel.Enabled = false;
Then clicking the Cancel button should take you into your code-behind function without confirmation at all.
EDIT: The ConfirmPopupExtender shouldn't be pointing to the btnCancel. Instead, it should be pointing to a hidden button (this is what the example in the link does).
<asp:Button ID="btnCancel" runat="server" CausesValidation="false"
OnClick="btnCancel_Click" Text="Cancel" OnClientClick="disableSubmit();return false;" />
<!-- This is the Hidden Buttons that you need to add and reference in the ConfirmButtonExtender -->
<asp:Button ID="HiddenButtonConfirm" runat="server" Text="" style="display:none;" />
<asp:Button ID="HiddenButtonModal" runat="server" Text="" style="display:none;" />
<ajaxToolKit:ConfirmButtonExtender ID="ConfirmButtonExtenderbtnCancel"
runat="server" DisplayModalPopupID="ModalPopupExtenderbtnCancel"
TargetControlID="HiddenButtonConfirm" BehaviorID="ConfirmButtonExtenderbtnCancel" />
<!-- You'll also want the ModalPopup to point to a seperate hidden button. -->
<ajaxToolKit:ModalPopupExtender ID="ModalPopupExtenderbtnCancel" runat="server"
BackgroundCssClass="modalBackground" CancelControlID="btnCancelCancel"
OkControlID="btnConfirmCancel" PopupControlID="ConfirmCancelPanel"
TargetControlID="HiddenButtonModal" />
This javascript might work:
var confirmbtn = $find('ConfirmButtonExtenderID');
confirmbtn.enabled =false;
//ConfirmButtonExtenderID needs to be the name of your ConfirmButtonExtender ID [:$]
I want to show a modal popup when a user click on an asp button. The user must select an option of a panel. The value of the option selected must be saved to an input hidden and then the asp.net button must do a PostBack.
Can I do that?
Thank you!
It is possible for a ModalPopupExtender to be displayed using a postback. You'll need an invisible target control. The extender is attached to this hidden control.
<asp:Button runat="server" ID="btnShowModal" Text="Show"
OnClick="btnShowModal_Click" />
<asp:Button runat="server" ID="HiddenForModal" style="display: none" />
<ajaxToolKit:ModalPopupExtender ID="Modal1" runat="server"
TargetControlID="HiddenForModal" PopupControlID="PopupPanel" />
In your message handler in code-behind, you'll show the ModalPopupExtender:
Modal1.Show();
And in the code you're using to dismiss the Modal, call the ModalPopupExtender's Hide function:
Modal1.Hide();
I use this method for showing a modal that displays detailed data that I retrieve from a database based on what's selected in a GridView.
Add your Button or LinkButton
<asp:Button ID="MyButton" Text="Click Here" runat="server" />
Add a Panel to hold your options with a DropDownList
<asp:Panel ID="MyPanel" runat="server">
<asp:DropDownList ID="MyDropDown" runat="server">
<asp:ListItem Value="1" Text="Option 1" />
</asp:DropDownList>
<asp:Button ID="SaveBtn" Text="Save" OnClick="Save_Click" runat="server" />
<asp:Button ID="CancelBtn" Text="Cancel" runat="server" />
</asp:Panel>
Add your ModelPopupExtender
<act:ModalPopupExtender ID="Mpe1" TargetControlID="MyButton"
CancelControlID="CancelBtn" PopupControlID="MyPanel" runat="server" />
Then add your code behind to the SaveBtn Button
public void SaveBtn_Click(object sender, EventArgs e) {
string selectedOption = MyDropDown.SelectedValue;
}
Finally, I've decided to use jQuery to show a ModalPopUp. The following question has the answer to this question:
jQuery UI's Dialog doesn't work on ASP.NET
If you are not agree, tell me.