I am trying to rebind my grid once a radwindow has been closed through master page. My grid is in a usercontrol in aspx page. In master page i have :
function CancelEdit() {
GetRadWindow().Close();
}
function CloseAndRebind() {
GetRadWindow().BrowserWindow.refreshGrid(); // Call the function in parent page
GetRadWindow().close(); // Close the window
}
function refreshGrid() {
$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
}
and I have the following javascript in the user conrtrol:
<script type="text/javascript" language="javascript">
function refreshGrid() {
$find("<%= RadAjaxManager.GetCurrent(me.Page).ClientID %>").ajaxRequest("Rebind");
}
</script>
Once I close update the database in radwindow i register a javascript:
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "mykey", "CloseAndRebind();", True)
I can see my data source changing but the grid doesn't get updated. any suggestions?
EDIT ::
The structure is something like this:
I have master page which has the RadAjaxManager.
There is a main page which has a user control
Another user control inside above user control which has the RadGrid
Then there is an aspx page that opens as radwindow
Use the client-side API to rebind your grid, should be the correct way to do that:
In your child page:
function refreshGrid() {
$find("<%= YourGrid.ClientID %>").get_masterTableView().rebind();
}
To call a javascript function from the parent page, simply use this:
function CloseAndRebind() {
GetRadWindow().get_contentFrame().contentWindow.refreshGrid(); // Call the function in parent page
GetRadWindow().close(); // Close the window
}
Related
I want to change div style (display) in master page from my child page ,
I used:
protected void ShowMsgText(int MsgID)
{
HtmlGenericControl MsgInner;
MsgInner =((HtmlGenericControl)Master.FindControl("MsgInner"));
MsgInner.Attributes["class"] = "MsgInnerShow";
}
The Problem :
I want to change the class from update panel , the div in master page Not in the update panel ,
any way to achieve this without need to move the update panel to master page .
Without the UpdatePanel you would use FindControl to change the class.
Panel panel = Master.FindControl("Panel1") as Panel;
panel.CssClass = "myClass";
But since you use an UpdatePanel, the easiest way is to use jQuery.
On the master page the Panel and the script
<asp:Panel ID="Panel1" runat="server">Welcome to StackOverflow</asp:Panel>
<script type="text/javascript">
function changeClass(className) {
$("#<%= Panel1.ClientID %>").attr("class", className);
}
</script>
Then in the code behind of the aspx page, you can call that javascript function on PostBack.
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "changeClassName", "changeClass('myClass');", true);
I have some processing that can take up to 5+ seconds the first time the page is loaded on the server. This is an external constraint that's beyond my control and since it's happening in a WebPart that can be added to any page on servers that are outside of my control, I can't do this processing at a larger scope such as the application.
I'd like the page to show progress while a partial postback happens in an updatepanel instead of the user waiting for the page to load before seeing anything at all. The code behind that postback will do the busy work.
I've tried using an ajax timer which works well except when there's an exception thrown in the code behind the postback.
In summary I would like to know how to perform a partial postback once and only once as soon as the page loads on the client.
I figured this out. To partial postback to the server via an UpdatePanel without using hidden controls, do this with jQuery:
<script type="text/javascript">
$(document).ready(function () {
__doPostBack('<%=UpdatePanel1.ClientID %>');
});
</script>
This will perform a partial postback to the server against the UpdatePanel with the ID UpdatePanel1 as soon as the HTML DOM is ready. You can then use the ASP.NET page life cycle to hook into whatever event is appropriate for you. I hooked into the load event of the update panel:
protected void UpdatePanel1_Load(object sender, EventArgs e)
{
if (Page.IsPostBack && Session["InitializedKey"] == null)
{
Session["InitializedKey"] = true;
// do your initialization stuff here
}
}
The code above will only run if the page is posting back and the session variable is set. Now you have to clear the session variable when the user refreshes the page since the intent here is to run this code on the first postback and only the first postback. So clear the session variable in the Page_Load:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
Session[initializedKey] = null;
}
And if you want to show a progress indicator while the page is in partial postback, do this javascript:
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
if (args._postBackElement.id == '<%=UpdatePanel1.ClientID %>') {
$get('Progress').className = 'Progress';
}
}
function EndRequestHandler(sender, args) {
if (sender._postBackSettings.sourceElement.id == '<%=UpdatePanel1.ClientID %>') {
$get('Progress').className = 'Hidden';
}
}
</script>
This requires a div tag with the id 'Progress' and whatever you want to show for progress within that div. You also need some css to set the display and visible styles on the div tag in classes named Hidden and Progress. Don't forget to perform error handling on partial postbacks!
I have the following javascript:
<script type="text/javascript">
function showjQueryDialog() {
$("#dialog").dialog("open");
}
$(document).ready(function() {
$("#dialog").dialog({
autoOpen: false,
modal: true,
buttons: { "Renew Membership": function() { $(this).dialog("close"); } }
});
});
</script>
I have an asp:Button on the page which logs the user it. This is the sample of what I want to occur when the button is clicked on the server-side:
protected void LoginButton_OnClick(object sender, EventArgs e)
{
UserProfile profile = UserProfile.GetUserProfile(txtUserName.Text);
TimeSpan ts = profile.Expiration.Subtract(DateTime.Now);
if(ts.Days <= 30)
//call showJQueryDialog() to open the dialog box
Page.ClientScript.RegisterStartupScript(typeof(Login2), "showjquery",
"showJQueryDialog();", true);
else
//log the user in as normal.
}
Also is how would I attach a method such as the following to the Renew Button on the Dialog
public void Renew()
{
Response.Redirect("Renew.aspx");
}
As calling client side function is not possible I would suggest to emit in javascript the information required for the decision and make everything happen on the client side.
Alternatively you can do need a page reload, as suggested from previous commenter.
if(ts.Days <= 30)
ScriptManager.RegisterStartupScript(
typeof(MyPage), "showjquery",
"$(document).ready(function() { showJQueryDialog(); };",
true
)
else
//log the user in as normal.
Put that right where you have: //call showJQueryDialog() to open the dialog box
Update 1: You seem to be using an update panel, in that case you need to use ScriptManager.RegisterStartupScript
Update 2: You also want to wrap the js call in a jquery .ready call, so it isn't triggered before the dialog has been configured. This is better than hooking up the body onload because onload waits for images to be loaded so .ready will show sooner (depending on the images and other bits of info loaded).
I really don't understand Freddy's approach to this at all. I am misunderstanding something maybe. The way I see it, there are only two possibilities here, as devdimi point out. Either:
a) Do all the logic in the client-side onClick javascript. You could call an AJAX method that performs the action in the server-side OnClick, then call your jQuery popup in the AJAX callback.
b) Do a postback, handle the server-side OnClick, then attach javascript for the page that runs in the body onLoad event:
body.Attributes.Add("onLoad", "showJQueryDialog();")
I would keep a hidden LinkButton and then call the __doPostBack method in javascript.
<asp:LinkButton runat="server" ID="Renew" OnClick="Renew_Click" style="display:none" />
jQuery
$(document).ready(function() {
$("#dialog").dialog({
autoOpen: false,
modal: true,
buttons: { "Renew Membership": function() {
$(this).dialog("close");
__doPostBack('Renew', '');
// or if inside a master page something like this
__doPostBack('ctl00$ContentPlaceHolder1$Renew', '');
} }
});
});
I have a somewhat similar issue with IE8.
We're using ASP.NET and anytime we do a Response.Redirect within the PageLoad/Control-Events IE8 sets all the base DOM objects to undefined (Image, window, document)
But if we do the redirect during the PreInit event then IE8 is fine.. Lovely
I have an asp.net page with a save button within an updatepanel and contenttemplate. The save works nicely, but I am trying to add a "wait" gif while the save is happening using JQuery, but the ajaxStart event is not firing. I put a simple catch shown below:
$(document).ajaxStart(function () {
alert('starting');
}).ajaxStop(function () {
alert('done');
});
No alerts show when I click the save. Is there a problem when trying to capture ASP.net Ajax events, is asp doing some funky type of Ajax calls that can't be captured by Jquery?
Thanks, let me know if you have any ideas about this,
Mark.
The ASP.NET update panels seem to do their own thing... Tap into the PageReuqestManager and setup your own calls here...
EDIT
I simplified the functions a bit below to match your sample a little more...
<script type="text/javascript">
function pageLoad() {
if (!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(AjaxEnd);
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(AjaxBegin);
}
}
function AjaxEnd(sender, args) {
alert("I am done...");
}
function AjaxBegin(sender, args) {
alert("I am about to start...");
}
</script>
Im executing javascript on a master page that is onClick event of a Menu item i set it to a hidden field and on Init of the Master page im not able to access this hidden field value.
Regards
State isn't available in your controls until the Load phase. Before that you have to check in Request.Form
This is the Code. In Master Page, I add the tag
<asp:HiddenField ID="hdnPath" runat="server" Value=""/>
Then I have a script tag which runs a function setScript() that is every time Master Page is loaded
<script type="text/javascript" language="javascript">
setScript();
// I Navigate through all the menu items, which is navigate
// through all the "a" tags and then all of the a tags onclick
// event i add a new function ,below is the code
<script type="text/javascript" language="javascript">
setScript();
function setScript() {
var objMenu=document.getElementById('<%=_menu.ClientID %>');
var objHyperLinks=objMenu.getElementsByTagName('a');
for(var i=0;i<objHyperLinks.length;i++) {
var pageLoc=objHyperLinks[i].href;
objHyperLinks.item(i).onclick=function (){
return setEvent(this);
};
}
}
function setEvent(Loc) {
var pageLoc=Loc+"";
var iframePath=document.location.href;
var targetPath=pageLoc;
document.getElementById('<%=hdnPath.ClientID %>').value=targetPath;
if(document.all) {
document.all.frameLoader.src=targetPath;
} else {
var frame=window.frames;
frame[0].location.href=targetPath;
}
return false;
}
I alert the value of hdnPath right after the targetPath is assigned and I get to see the assigned value.