How to call the usercontrol in js file.

Posted by Rahamtu under jQuery on 1/23/2012 | Points: 10 | Views : 3550 | Status : [Member] | Replies : 5
hi,

i have a js file i want to call usercontol in it.how can i call.

rahamath


Responses

Posted by: Blessyjees on: 1/24/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Can you tell the purpose for calling usercontrol in js file.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Rahamtu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rahamtu on: 1/24/2012 [Member] Starter | Points: 25

Up
0
Down
i have created one widget in usercontol.so i need to use that one in another place.in that place is created in js file so that i need to call there.

rahamath

Rahamtu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 1/24/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
function LoadNewScreen()

{
window.open("Sample.ascx");
return false;

}


try this

Regards,
Susan

Rahamtu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rahamtu on: 1/24/2012 [Member] Starter | Points: 25

Up
0
Down
i dont want to to open in a new window and i want to display in a div in same page itself.

rahamath

Rahamtu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hemanthlaxmi on: 1/25/2012 [Member] Starter | Points: 25

Up
0
Down
You need to Design a user Control and Call the User Control in the other page.

See this example i hvae done in my project
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoadControlDynamically.aspx.cs"

Inherits="LoadControlDynamically" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Load asp.net web user control using jQuery and web method</title>
<style type="text/css">
.btn_style
{
background-color: Aqua;
font-family: Verdana;
font-size: smaller;
}
</style>
<%-- <link href="Styles/Site.css" rel="stylesheet" type="text/css" />--%>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="http://github.com/malsup/blockui/raw/master/jquery.blockUI.js?v2.34"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#Button1').click(function () {
$.blockUI({ message: '<h1>Processing ....</h1>' });
var controlName = "UserControls/WebUserControl.ascx";
$.ajax(
{
type: "POST",
url: "LoadControlDynamically.aspx/RenderControl",
data: "{controlName:'" + controlName + "'}",
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (response) {
$.unblockUI();
$('#result').html(response.d);
},
failure: function (msg) {
$.unblockUI();
alert(msg);
$('#result').html(msg);
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>
Load asp.net web user control using jquery
</h2>
<p>
<input type="button" id="Button1" value="Load Control" class="btn_style" />
<div id="result">
&nbsp;</div>
</p>
</div>
</form>
</body>
</html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class LoadControlDynamically : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

[WebMethod]
public static string RenderControl(string controlName)
{
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(form);

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



If this helps you .
Please "Mark as Answer"

Rahamtu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response