Click here to Skip to main content
15,920,031 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to call a ascx page from Javascript function of aspx page
or

reload a ascx page via button click of aspx page

i used like this but no use
 function refresh(){ 
__doPostBack('<%=upNotes.ClientID %>', 'addTocart');
}


Help me to solve this issue

Thanks in advance
Posted
Updated 10-Apr-14 1:53am
v4
Comments
[no name] 10-Apr-14 8:08am    
Thanks for your reply. but want to reload a ascx from aspx page.your code might be pass message from ascx to aspx page

I don't think it's possible by requesting the ascx file directly--i.e. supplying "MyControl.ascx" as the url parameter to $.ajax(..). The ascx file isn't exposed directly by the web server.

supply the url of the aspx page containing the user control--i.e. if an instance of MyControl.ascx lives on MyPage.aspx you would have to supply "MyPage.aspx" as the url parameter.
 
Share this answer
 
Cant access .ascx directly you will only able to access .aspx in your case
 
Share this answer
 
Comments
[no name] 10-Apr-14 8:10am    
Explain the code
Sanket Saxena 10-Apr-14 8:13am    
why dont you call your ascx page control say "upNotes" from the same ascx page
[no name] 10-Apr-14 8:24am    
that is my need
First you try this, if this simple thing is working for you?

XML
//.ascx page
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyControl.ascx.cs" Inherits="app1.MyControl" %>
<script type="text/javascript">
    ShowMessage("hello world!");
</script>


//.aspx page
<%@ Register TagPrefix="uc" TagName="myControl" Src="~/MyControl.ascx" %>


 <script type="text/javascript">
     function ShowMessage(message) {
         alert(message);
     }
    </script>
 
Share this answer
 
Comments
Member 11410896 2-Feb-15 3:01am    
i m getting alert as undefined, it means i cannot access the user control??
--this may b helpful for u

--Jquery Code

JavaScript
$(document).ready(function () {
    LoadUserCOntrol();

});

function LoadUserCOntrol() {
    var ControlName = "UserControls/Common_UC.ascx";
    $.ajax({
        type: "POST",
        url: "CustomBooking.aspx/Result",
        data: '{ "controlName":"' + ControlName + '"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function (response, Control) {
            $('#sortable').append(response.d);
        },
        error: function (msg) {
            alert(msg);
            $('#sortable').html(msg.d);
        }
    });
}

C#
[WebMethod]
public static string Result(string controlName)
    {
        //Thread.Sleep(2000);
        try
        {
            Page page = new Page();
            UserControl userControl = (UserControl)page.LoadControl(controlName);
            userControl.EnableViewState = false;
            HtmlForm form = new HtmlForm();
            //form.Controls.Add(userControl);
            page.Controls.Add(userControl);

            StringWriter textWriter = new StringWriter();
            HttpContext.Current.Server.Execute(page, textWriter, false);
            return textWriter.ToString();
        }
        catch (Exception ex)
        {
            return ex.ToString();
        }
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900