I am using iframe to open new .aspx page from parent page. child page is using ajaxcontroltoolkit(ajax CalendarExtender). Now on form submit, I want to close iframe and return to parent page. For that I am using following code.
ClientScript.RegisterStartupScript(this.GetType(), "scriptid", window.parent.location.href='ViewVendors.aspx'", true);
This works file if I remove ajax control from child page but does not work with ajax control.
I want to use calenderExtender and iframe both. How can I use it and what is the problem for such so called abnormal behavior.
This is the code for my submit button event handler.
protected void btnUpdate_Click(object sender, EventArgs e)
{
try
{
objVendor.VendorID = Convert.ToInt64(Request.QueryString["Id"]);
objVendor.Name = txtName.Text;
objVendor.BillingAddress = txtBillingAddress.Text;
objVendor.ShippingAddress = txtShippingAddress.Text;
objVendor.ContactPersonName = txtContactPerson.Text;
objVendor.ContactNumber = txtContactNumber.Text;
objVendor.EmailID = txtEmailID.Text;
objVendor.VendorSinceDate = Convert.ToDateTime(txtVendorDate.Text);
objVendor.IsActive = Convert.ToBoolean(rdblStatus.SelectedValue);
objVendor.Logo = FileUpload();
int intResult = objVendor.UpdateVendor();
if (intResult > 0)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "window.parent.location.href='ViewVendors.aspx'", "scriptid", true);
//ClientScript.RegisterStartupScript(this.GetType(), "scriptid", "window.parent.location.href='ViewVendors.aspx'", true);
}
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
lblMessage.CssClass = "ERROR";
}
}
//Edit
Now my code works fine as long as I am not adding calender extender to the child page.
When I add calender extender in child page it shows error "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)". If I remove calender extender, again it works well. By doing some googling, I found that <% %> in Javascript tag is creating problem. How can I solve it and why calender control is creating problem in such cases?
Here is the code for my script.
<script type="text/javascript">
function uploadStarted() {
$get("imgDisplay").style.display = "none";
}
function uploadComplete(sender, args) {
var imgDisplay = $get("imgDisplay");
// var imgPhoto = $get("#imgPhoto");
var imgPhoto = document.getElementById('<%=imgPhoto.ClientID %>');
imgDisplay.src = "images/loader.gif";
imgPhoto.style.display = "none";
imgDisplay.style.cssText = "";
var img = new Image();
img.onload = function () {
imgDisplay.style.cssText = "height:100px;width:100px";
imgDisplay.src = img.src;
};
img.src = "<%=ResolveUrl(UploadFolderPath) %>" + args.get_fileName();
}
</script>
You need to register your JavaScript using the ScriptManager instance on your page - which you should already have if you're using AJAX. It has its own RegisterStartupScript method that you can use.
Related
Currently I'm have around 2000 building data which is being loading in the listbox due to which the page loads slowly and I want load only i.e 10 building on page load so that page could load faster and other UI control could load faster.
tried:
For this I've added the result of grid in session so when the user clicks on the particular link in grid it does not hit the SP/database and get result from session but it does not help much.page
loading still is slow
So is there any other way to load the Listbox faster ?
adding the code
code .aspx
<asp:ListBox ID="drpBuilding" runat="server" CssClass="formcontrol"SelectionMode="Multiple"></asp:ListBox>
c# code
protected void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack) {
this.drpBuilding.Items.Clear();
List<PResponse.BLL.Building> lstBuildings = default(List<PResponse.BLL.Building>);
if (Session["buildinglist"] == null) {
lstBuildings = this.mBuildingBLL.Get_ContactSiteBuildingsListLoad(p_ContactID: UserWrapper.GetCurrentUser().ContactID, p_ShowInactive: false);//SP method
Session["buildinglist"] = lstBuildings;
} else {
lstBuildings = Session["buildinglist"]; //not hitting the SP/DB getting value from SP
}
if (lstBuildings.Count > 0) {
this.drpBuilding.Enabled = true;
this.drpBuilding.DataSource = lstBuildings;
} else {
this.drpBuilding.Enabled = false;
}
this.drpBuilding.DataTextField = "Building";
this.drpBuilding.DataValueField = "BuildingID";
this.drpBuilding.DataBind();
}
}
I have an unexpected behavior of two JS which get called when I click on a control.
These JS are supposed to be called only when the button in the Tree list is clicked under specific conditions.
Right now the JS "message alert" is called even if a click on any of the node of the tree list when the conditions apply.
The other JS, which open a window, also opens when a node of the tree list is clicked, but after having opened and closed it at least one time.
protected void RadTreeList1_ItemCommand(object sender, TreeListCommandEventArgs e)
{
string idMessage = "";
if (e.CommandName == "Select")
{
if (e.Item is TreeListDataItem)
{
TreeListDataItem item = e.Item as TreeListDataItem;
idMessage = item.GetDataKeyValue("MessageID").ToString();
}
}
addMessage(idMessage);
}
private void addMessage(string idMessage)
{
if (Label1.Text =="" || Label1.Text==null )
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('You shall be logged-in to post and replay to messages');", true);
}
else
{
{
Session["fatherMessageID"] = idMessage;
string script = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(ShowWindow);</script>";
ClientScript.RegisterStartupScript(this.GetType(), "showWindow", script);
}
}
}
Function which opens the window:
function ShowWindow() {
var oWnd = window.radopen('Window1.aspx', 'window1');
}
Function which close the window from inside the window:
function GetRadWindow() {
var oWnd = null;
if (window.radWindow) oWnd = window.radWindow;
else if (window.frameElement.radWindow) oWnd = window.frameElement.radWindow;
return oWnd;
}
function CloseWindow() {
var oWnd = GetRadWindow();
oWnd.close()
}
Function which calls the CloseWindow inside the window page:
finally
{
string script = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(CloseWindow);</script>";
ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", script);
}
How can I fix this issue?
Alert Issue:
you need to place addMessage(idMessage); inside if (e.Item is TreeListDataItem) condition
Dialog Issue:
not sure whether window.radopen('Window1.aspx', 'window1') is correct or not. if you are using RadWindow then showwindow function should be something like this var oWnd = window.radopen(null, "[RadWindowID]");
my process is when user click button print in first form then process is redirect to second page. Now when second page is showed i want to call jquery .How can i do , Please help. because i want to get html from second page.
this is my code in web
<script>
$(function () {
setTimeout(function () { printForm() }, 3500);
function printForm() {
window.onload(function () {
<%testMethod();%>
});
}
});
</script>
this is my code in code behide
public void testMethod() {
if (!Page.IsPostBack)
{
WebClient MyWebClient = new WebClient();
string html = MyWebClient.DownloadString(Session["url"].ToString());
}
}
But the problem is testMethod is calling before scond page is show. i want to do like window.print()
If I understand you correctly, you want to get jquery when other page loads, to do that with js only, you have to do something like this:
your_server ="some_server_name"
(function() {
var jquery_scrpt = document.createElement('script'); jquery_scrpt.type = 'text/javascript'; jquery_scrpt.async = true;
jquery_scrpt.src = 'https://' + your_server + '//code.jquery.com/jquery-1.11.2.min.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(jquery_scrpt);
})();
this will add jquery dynamically to your page.Hope that helps.
Objective:- From the server-side, I need to open a radwindow(defined in JavaScript of the aspx page) automatically on an IF condition.
Code used:-
In aspx page, I defined the radwindow as:-
<telerik:RadWindowManager Skin="WBDA" ID="AssetPreviewManager" Modal="true"
EnableEmbeddedSkins="false" runat="server" DestroyOnClose="true" Behavior="Close"
style="z-index:8000">
<Windows>
<telerik:RadWindow ID="DisclaimerAlertWindow" runat="server" Width="720px" Height="220px"
Modal="true" visibleStatusbar="false" VisibleTitlebar="false" keepInScreenBounds="true" title="Sourav">
</telerik:RadWindow>
</Windows>
</telerik:RadWindowManager>
In JavaScript, a function is defined for opening the radwindow:-
function openRadWindow()
{
var oWnd = radopen('DisclaimerAlert.aspx, 'DisclaimerAlertWindow');
oWnd.set_title('Access Denied !');
oWnd.Center();
return false;
}
So on the server side of the aspx page, In the Page Load event an IF condition is checked and then I'm calling 'openRadWindow()' function as:-
protected void Page_Load(object sender, EventArgs e)
{
if (fieldValue == "False")
{
string xyz = "<script type='text/javascript' lang='Javascript'>openRadWindow();</script>";
ClientScript.RegisterStartupScript(this.GetType(), "Window", xyz);
}
}
Problem:-
But on running this, these JavaScript errors are coming:-
Object doesn't support this property or method.
'undefined' is null or not an object
Please help how to achieve my objective. I am totally stuck.
Hi I want to share with you my solution to create RadWindow dialog in Javascript code only.
We need to implement 2 methods: one for initializing RadWindow dialog, and the last one for recieving the arguments returned after closing the RadWindow. You can do what you want in this second step (e.x postback,...)
Here is my code:
Initializing RadWindow dialog:
function openMyDialog(url, args) {
var manageWindow = GetRadWindowManager();
if (manageWindow) {
var radWindow = manageWindow.open(url, "<your_dialog_name>");
if (radWindow) {
radWindow.set_initialBehaviors(Telerik.Web.UI.WindowBehaviors.None);
radWindow.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Resize);
radWindow.setActive(true);
radWindow.SetModal(true);
radWindow.center();
radWindow.set_visibleStatusbar(false);
radWindow.set_keepInScreenBounds(true);
radWindow.set_minWidth(640);
radWindow.set_minHeight(480);
radWindow.setSize(640, 480);
radWindow.set_destroyOnClose(true);
radWindow.add_close(closeMyDialog);//after closing the RadWindow, closeMyDialog will be called
radWindow.argument = args;//you can pass the value from parent page to RadWindow dialog as this line
}
}
}
Closing the RadWindow dialog:
function closeMoveProjectDialog(sender, args) {
var objArgs = args.get_argument();
//objArgs variable stored the values returned from the RadWindow
//you can use it for your purpose
}
How to call this?
You can put the open method into your expected method. In my side, I have a method as shown below and I will call the RadWindow as this way:
function ShowForeignKeyFrontEditSingle(param1, param2){
var url = "ForeignKeyFrontEditSingle.aspx";
var objArgs = new Array();
objArgs[0] = param1;
objArgs[1] = param2;
openMyDialog(url, objArgs);
return;
}
Of course, you have to declare a RadWindowManager control
function GetRadWindowManager() {
return $find("<%=your_radwindow_manager_control.ClientID%>");
}
Take a look here, it explains how to use the ScriptManager.RegisterStartupScript method: http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-javascript-from-server-side.html. Note it the ScriptManager's method. Also look at the Sys.Application.Load event to prevent your code from executing too early.
I have multiple update panels with various asp buttons on a single page. I want to disable the buttons which caused the postback in update panel untill it completes.
Is there a way to avoid using a third party control for this? through JQuery or any other method ?
You can either do this:
cs
//in pageload
//the request is not in postback or async mode
bt1.OnClientClick = "this.disabled = true; " + ClientScript.GetPostBackEventReference(bt1, null) + ";");
Note: you can replace "this.disabled = true" with a js function that will have better handling for disabling the button and maybe display a friendly message as well.
Or this:
http://msdn.microsoft.com/en-us/library/bb383989.aspx
js
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(CheckStatus);
function CheckStatus(sender, arg)
{
var postBackElement = arg.get_postBackElement();
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm.get_isInAsyncPostBack() && postBackElement.id == "btn1") {
arg.set_cancel(true);
//display friendly message, etc
}
}
Note: I modified it so it checks for the button's id. Replace "btn1"
Good luck!!
You can use the start and stop message of the update panel to disable your controls.
For example
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
function InitializeRequest(sender, args) {
document.getElementById("ButtonToDisable").disabled = true;
}
function EndRequest(sender, args) {
document.getElementById("ButtonToDisable").disabled = false;
}
</script>