I want to close the RadWindow and refresh the parent : how to do this server side :
I have the following case:
Two pages say :
parent.aspx :
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableViewState ="false">
</telerik:RadWindowManager>
and parent.cs
protected void OpenNewWindow(string url, int width, int height,int mode)
{
RadWindow newWindow = new RadWindow();
newWindow.NavigateUrl = url;
newWindow.VisibleOnPageLoad = true;
newWindow.KeepInScreenBounds = true;
if (width > 0)
{
newWindow.Width = width;
}
if (height > 0)
{
newWindow.Height = height;
}
newWindow.VisibleStatusbar = false;
if (mode == 0)
{
newWindow.DestroyOnClose = true;
newWindow.InitialBehaviors = WindowBehaviors.Maximize;
}
RadWindowManager1.Windows.Add(newWindow);
}
i call this method in the rowcommand of some gridview on my parentpage :
like this :
OpenNewWindow("child.aspx", 0, 0,0);
Now i want on the server side click event of some button on the child page to close the rad window and refresh the parent one how to do this ??
As you said, you want to close from code behind. So you can render Page.ClientScript.RegisterClientScriptBlock(GetType(), "CloseScript", "refreshParentPage()", true); from code behind to refresh the parent.
Just add the following code and script in Child Page. No code is needed in parent page.
<script>
function getRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
// Reload parent page
function refreshParentPage() {
getRadWindow().BrowserWindow.location.reload();
}
</script>
<asp:Button runat="server" Text="Close" ID="CloseButton"
OnClick="CloseButton_Click"/>
protected void CloseButton_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptBlock(GetType(),
"CloseScript", "refreshParentPage()", true);
}
Update:
// Redirect page page to url
function redirectParentPage(url) {
getRadWindow().BrowserWindow.document.location.href = url;
}
// Code behind
Page.ClientScript.RegisterClientScriptBlock(GetType(),
"CloseScript", "redirectParentPage('Parent.aspx')", true);
You should use the getRadWindow().close() method and the OnClientClose event.
On Child.aspx:
<script type="text/javascript">
function getRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function clientClose(arg) {
getRadWindow().close(arg);
}
</script>
In Child.cs:
protected void btn_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(Page, typeof(Page), "closeScript", "clientClose('');", true);
}
When creating your RadWindow in Parent.cs, add the OnClientClose event: newWindow.OnClientClose = "OnChildWindowClosed";.
And on Parent.aspx:
<script type="text/javascript">
function OnChildWindowClosed(sender, eventArgs) {
document.location.reload(); // there may be a cleaner way to do the refresh
}
</script>
Simple way to force closing rad window, just put it inside update panel like that :
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Block">
<ContentTemplate>
<telerik:RadWindow ID="RadWindow1" runat="server">
<ContentTemplate>
</ContentTemplate>
</telerik:RadWindow>
</ContentTemplate>
</asp:UpdatePanel>
Important: you have to apply this properties to the update panel :
UpdateMode="Conditional" RenderMode="Block"
then inside the button you want to execute the close command perform :
UpdatePanel1.update()
this command will close radwindow and no refresh to your Webpage and no need to javascript, I tried it.
Related
Hello i am failing to pass the value from dropdownlist in the parent aspx form to textbox in the child aspx form
Parent javascript
: The First script is to open the popup window
<script type="text/javascript">
var popup;
function NewCustOpn() {
popup = window.open("NewCustomer.aspx","Popup",toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=0,width=520,height=350,left = 250,top = 50");
}
</script>
This is the second script on the parent page to get the value of the dropdownlist
<script type = "text/javascript">
function parentFunc()
{
return document.getElementById ("<%=DropDownList1.ClientID%>").value;
}
</script>
The child page javascript:
<script type = "text/javascript">
window.onload = function ()
{
if(window.opener != null && !window.opener.closed)
{
var val = window.opener.parentFunc();
var textbox = document.getElementById("<%=TextBox1.ClientID%>");
textbox.Value = val;
}
}
</script>
When the popup opens TextBox1 is empty.
Your problem is simple. Just replace the below line from your child page's js function
textbox.Value = val;
to
textbox.value = val; // lowercase "v"
or justdo a direct assignment like this
document.getElementById("<%=TextBox1.ClientID%>").value = val;
Or another possible solution would be to directly pass the required value from the parent page as a querystring value and you don't need the js function in the popup page. The querystring value you can access it in child pages's page load event and assign it directly to the textbox.
Your Parent js
function NewCustOpn() {
var ddlvalue = document.getElementById("<%=DropDownList1.ClientID%>").value;
var popup = window.open("Popup.aspx?dropdownval=" + ddlvalue, "Popup", "toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=0,width=520,height=350,left = 250,top = 50");
}
And from you child page's code behind
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString["dropdownval"])) {
TextBox1.Text = Request.QueryString["dropdownval"];
}
}
I am using Telerik RadControls in my project and and have a menu where I have an 'About' button. When I click the 'About' button a window pops up describing the application. The problem is if I refresh the page or navigate to another page then back to the first page the window automatically pops up.
The goal is only have that window pop up when the user clicks the about button.
here is the code I used to get that window:
<!--About Window-->
<telerik:RadWindowManager runat="server" EnableViewState="false" KeepInScreenBounds="true"></telerik:RadWindowManager>
<telerik:RadWindow ID="AboutMenu" Behaviors="Close" Animation="None" runat="server" Width="360px" KeepInScreenBounds="true" Height="360px" Modal="true" VisibleStatusbar="false" Skin="Glow">
<ContentTemplate>
<p style="text-align: center;">Sample Window Information</p>
</ContentTemplate>
</telerik:RadWindow>
Javascript
function OnClientItemClick(sender, eventArgs) {
if (window.args.get_item().get_text() == "About") {
var radwindow = window.$find(window.AboutMenu.ClientID);
window.args.set_cancel(true);
}
}
.cs
protected void MainMenu_OnItemClick(object sender, RadMenuEventArgs e)
{
if (e.Item.Text == "About")
{
AboutMenu.VisibleOnPageLoad = true;
}
}
The window works but it loads whenever the page loads and thats where I think the line AboutMenu.VisibleOnPageLoad = true comes into play and is causing the error but when I take out that line it won't display at all.
Instead of using VisibleOnPageLoad try using the following code to open the window on itemclick.
protected void MainMenu_OnItemClick(object sender, RadMenuEventArgs e)
{
if (e.Item.Text == "About")
{
string script = "function f(){$find(\"" + RadWindow1.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
}
}
Or, just use the OnCLientItemClicking event of the menu to open the RadWindow and cancel the postback. But you will need to fix you JS code, because the arguements are in the context of the current function. ALso, the reference to RW may break unless you have made your own array of ClientIDs.
function OnClientItemClicking(sender, eventArgs) {
if (eventArgs.get_item().get_text() == "About") {
var radwindow = window.$find(<%=AboutMenu.ClientID%>);
radwindow.show();
eventArgs.set_cancel(true);
}
}
Trying to pass value (abc) from code-behind to JavaScript but the page fails and doesn't load. Is there something wrong with the syntax? I've noticed that normally the <%...%> is highlighted yellow but this is not the case in my code.
<script src="../Scripts/jqModal.min.js" type="text/javascript"></script>
<script type="text/javascript">
$().ready(function() { });
$("a").click(function() {
if (this.id == "optionalFeatures_Online") {
var abc = "<%=Variable_codebehind %>";
}
});
</script>
Code Behind On_Load event:
protected override void OnLoad(EventArgs e)
{
Variable_codebehind = "hello world";
}
Error from logfile:
Web.HttpUnhandledException' was thrown. ---> System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
first bind the value to a hidden control
then get the value from the hidden control
<script src="../Scripts/jqModal.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("a").click(function() {
if (this.id == "optionalFeatures_Online") {
var abc = <%=Variable_codebehind %>;
}
});
});
</script>
Code Behind On_Load event:
protected override void OnLoad(EventArgs e)
{
Variable_codebehind = HttpUtility.JavaScriptStringEncode("hello world", true);
}
You can use Page.RegisterStartupScript and pass some variables from Code-Behind. Place the script in a .js file and call it on OnLoad method from the code-behind:
OnLoad CodeBehind:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", String.Format("MyScript({0});", codeBehindVar));
MyScript.js
function MyScript(myVar)
{
var self = this;
$("a").click(function() {
if (this.id == "optionalFeatures_Online") {
var abc = self.myVar;
}
}
I am using a Tree View Hierarchy inside the UpdatePanel. The ASP.NET code is:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:TreeView ID="HierarchyTreeView" runat="server" meta:resourcekey="HierarchyTreeViewResource1" EnableViewState="true"></asp:TreeView>
</ContentTemplate>
</asp:UpdatePanel>
and on code behind i am writing
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
HierarchyTreeView.PathSeparator = CaseListPresenter.PathSeparator;
HierarchyTreeView.TreeNodePopulate += new TreeNodeEventHandler(HierarchyTreeView_TreeNodePopulate);
HierarchyTreeView.SelectedNodeChanged += delegate {
Presenter.CancelChangeFlag();
Presenter.SelectedNodeChanged();
CheckPreview();
};
}
If I am using TreeView outside the UpdatePanel my OnInit is working well. But, if I am using TreeView inside the UpdatePanel, it is not working properly. I want to maintain the scroll position of my tree view
Now finally i got the solution with this..
Maintain Panel Scroll Position On Partial Postback ASP.NET
TreeView is not fully supportive with update panel.
we can maintain the scroll position by using following script:
<script language="javascript" type="text/javascript">
var IsPostBack = '<%=IsPostBack.ToString() %>';
window.onload = function() {
var strCook = document.cookie;
if (strCook.indexOf("!~") != 0) {
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS + 2, intE);
if (IsPostBack == 'True') {
document.getElementById("<%=Panel4.ClientID %>").scrollTop = strPos;
}
else {
document.cookie = "yPos=!~0~!";
}
}
}
function SetDivPosition() {
var intY = document.getElementById("<%=Panel4.ClientID %>").scrollTop;
document.title = intY;
document.cookie = "yPos=!~" + intY + "~!";
}
</script>
call the setDivPosition() on ur Panel4
Its not executing statements in if block in my method
Master Page:-
page load event:-
Control c = new Control();
DoSomething(c);
My method:-
protected void DoSomething(Control control)(
{
foreach (Control c in control.Controls)
{
if(typeof(c).Equals(Telerik.Web.UI.RadEditor))
{
Telerik.Web.UI.RadEditor rad = c as Telerik.Web.UI.RadEditor;
label1.Visible = true; label1.Text = "dhchk";
rad.CssFiles.Add("~/styles/myStyle.css");
rad.CssFiles.Add("~/styles/myStyle2.css");
rad.CssFiles.Add("~/styles/myStyle3.css");
}
else
{
DoSomething(c);
}
}
}
my content page:-
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<telerik:RadEditor ID="Editor1" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins=false runat="server">
</telerik:RadEditor>
<telerik:RadEditor ID="Editor2" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins=false runat="server">
</telerik:RadEditor>
[EDIT] ok when debugging..I rt clicked "c" and then Quick watch...it says "The name 'c' does not exist in the current context" (?!?!) how so ?
Well, the Master page renders first so you won't have access from the master page to any of the content page controls. You can achive this using events and passing the control from the content to the master
udpate:
Again - Accessing user controls from the master page is flaw in the whole master->content design. the closest thing I can imagine is adding static function
public static void AddDesign(RadEditor obj)
{
...
}
and then call the function form the Page_Load of the user control
MASTER_PAGE_CLASS_NAME.AddDesign(RadEditor1);
Well, I'm not sure, you can access controls in page like this.
At first: that editor should be probably in some Panel (or some other container), so i should look like this:
<asp:Panel ID="pnl1" runat="server">
<telerik:RadEditor ID="Editor1" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins=false runat="server" />
<telerik:RadEditor ID="Editor2" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins=false runat="server" />
</asp:Panel>
Then try this:
protected void Page_Load(object sender, EventArgs e)
{
foreach (Controls c in pnl1.Controls)
{
if (c is Telerik.Web.UI.RadEditor)
{
// do you stuff ...
}
}
}
You should change things around and call your MasterPage method from the content control.
In your masterpage add the method:
public void DoSomething(Telerik.Web.UI.RadEditor rad)
{
label1.Visible = true; label1.Text = "dhchk";
rad.CssFiles.Add("~/styles/myStyle.css");
rad.CssFiles.Add("~/styles/myStyle2.css");
rad.CssFiles.Add("~/styles/myStyle3.css");
}
Call the function from an appropriate event in your page/content control. eg Page.Load, Editor1.Load etc
Master.DoSomething(Editor1);
Update
From the masterpage, you should search for child controls in the Content controls
ContentPlaceHolder1.FindControl("Editor1");
or you could try something like:
foreach (Control c in ContentPlaceHolder1.Controls)
{
if(typeof(c).Equals(Telerik.Web.UI.RadEditor))
{
Telerik.Web.UI.RadEditor rad = c as Telerik.Web.UI.RadEditor;
label1.Visible = true; label1.Text = "dhchk";
rad.CssFiles.Add("~/styles/myStyle.css");
rad.CssFiles.Add("~/styles/myStyle2.css");
rad.CssFiles.Add("~/styles/myStyle3.css");
}
else
{
DoSomething(c);
}
}
The load and render events of the master page are fired after those of the content page (as said here). Hence the controls in the content page should be available by the time these two events are fired?