Microsoft JScript runtime error: ‘Sys’ is undefined


Hi

I was getting this error while working on asp.net 2.0.

Microsoft JScript runtime error: ‘Sys’ is undefined

This error will come mainly due to this reasons
1. If you are using ajax control and if you donot have keep “ajax enabled web confi file”.Then it will throw this error.

To solve this problem, you have to keep ajax enable web confi file like this,you have to add in system.web tag in web confi file

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>

or you have to remove ajax control from your project.

How to use output parameter in store Procedure ?


Output parameter is used to pass the value after execution of sqlquery.
For example , tblemp table is there with Id,EmpName,EmpSal , I have to insert record on that table and I have to fetch the latest EmpId from tblemp for other operation then we can use Output parameter in storeprocedure like this example. It will avoid the multiple time database hit.

Store procedure for insert

ALTER PROCEDURE [dbo].[InsertEmpSp_WithOutPutParameter]
— Add the parameters for the stored procedure here
@EmpName varchar(150),
@EmpSal varchar(150),
@Id int output
AS
BEGIN
— SET NOCOUNT ON added to prevent extra result sets from
— interfering with SELECT statements.
SET NOCOUNT ON;

— Insert statements for procedure here
insert into tblEmp(EmpName,EmpSal) values(@EmpName,@EmpSal)

set @Id=SCOPE_IDENTITY()
return @Id

END

Code behind page is like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class OutPut_ParaMeter_Sp : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=ITTIOS02;Initial Catalog=Test;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{

}
protected void BtnSubmit_Click(object sender, EventArgs e)
{
string curId = "";
using (SqlCommand cmd = new SqlCommand("InsertEmpSp_WithOutPutParameter", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@EmpName", txtEmpName.Text);
cmd.Parameters.AddWithValue("@EmpSal", txtEmpSal.Text);
cmd.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output;
using (con)
{
con.Open();
cmd.ExecuteNonQuery();
curId = cmd.Parameters["@Id"].Value.ToString();
con.Close();
}

txtEmpName.Text = "";
txtEmpSal.Text = "";
Label1.Text = "Data has been inserted sucessfully.Current latest EmpId is " + curId;
}

}
}

How to make div/panel visible on basis of radiobuttonlist selection ?


Hi

If we have to do this task on client side without using postback then we can do using Javascript like this

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
<title></title>

<script type="text/javascript">

function HidDiv()
{
document.getElementById(‘Div1’).style.display = "none";
document.getElementById(‘Div2’).style.display = "none";
}

function showhidesearch()
{
var radio1=document.getElementById(‘<%=RadioButtonList1.ClientID %>’);

var rblopts = radio1.getElementsByTagName("input");

if(rblopts[0].checked)
{
document.getElementById(‘Div1’).style.display="block";
document.getElementById(‘Div2’).style.display="none";
}
else if(rblopts[1].checked)
{
document.getElementById(‘Div2’).style.display="block";
document.getElementById(‘Div1’).style.display="none";

}
}

</script>

</head>

<body onload = "javascript:HidDiv();">
<form id="form1" runat="server">
<div style="margin-left:200px;">

<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal" style="font-weight: 700"
onclick="showhidesearch()" >
<asp:ListItem Value="1">First Div</asp:ListItem>
<asp:ListItem Value="2">Second Div</asp:ListItem>
</asp:RadioButtonList>
<br />

<div id="Div1" style="background-color:Blue; width:200px; height:200px;" runat="server">
<br />
<b> This is the first div </b>

</div>
<br />
<br />

<div id="Div2" style="background-color:Lime; width:200px; height:200px;" runat="server">
<br />
<b> This is the Second div</b>

</div>

</div>
</form>
</body>
</html>

Textbox visible on basis of other selection in dropdown using Javascript



Hi

If our requirement is make visible the textbox field while “other” selection on dropdown then we can achieve using so many ways .

For example using Javascript,Jquery,or autopostback event on dropdown. But javscript or jquery is the best method to do this task. It will avoid the post back on server so performance of page will be faster.

 



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="JavaScriptTest.aspx.cs" Inherits="JavaScriptTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
<title></title>

<script type="text/javascript">

function Unvisible()
{
document.getElementById("TextBox1").style.visibility="hidden";
}

function FilterStatus()
{
var drpFilterType = document.getElementById("drpFilterType");
var selectedFilterType = drpFilterType
.options[drpFilterType.selectedIndex].value;

if (selectedFilterType == "Other")
{

document.getElementById("TextBox1").style.visibility="visible";

}

else
{
document.getElementById("TextBox1").style.visibility="hidden";
}

}
</script>

</head>
<body onload = "javascript:Unvisible();">
<form id="form1" runat="server">
<div>
<asp:dropdownlist id="drpFilterType" runat="server"
onchange="return FilterStatus()" >
<asp:ListItem Value="MonthFilter">Month</asp:ListItem>
<asp:ListItem Value="YearFilter">Year</asp:ListItem>
<asp:ListItem Value="Other">Other</asp:ListItem>
</asp:dropdownlist>

<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>