Do various things by JSON in ASP.net -1
Simply Add/Edit records by JSON
Form Design
Form Source
<div>
<table>
<tr>
<td align="right">
<asp:Label ID="Label4143"
runat="server"
ForeColor="Red"
Text="*"></asp:Label>
<asp:Label ID="Label1" runat="server"
Text="RFQ
Issue"></asp:Label>
</td>
<td align="left">
<table>
<tr>
<td>
<asp:TextBox ID="txt_RFQIssue"
runat="server"
Width="81px"
onkeydown="return
false;"
onpaste="return
false;"></asp:TextBox>
</td>
<td>
<asp:ImageButton ID="IB_RFQIssue"
runat="server"
ImageUrl="~/App_Themes/images/date.png"
/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="Label4144"
runat="server"
ForeColor="Red"
Text="*"></asp:Label>
<asp:Label ID="Label4" runat="server"
Text="Clarification
Meeting"></asp:Label>
</td>
<td align="left">
<table>
<tr>
<td>
<asp:TextBox ID="txt_ClarificationMeeting"
runat="server"
Width="81px"
onkeydown="return
false;"
onpaste="return
false;"></asp:TextBox>
</td>
<td>
<asp:ImageButton ID="IB_ClarificationMeeting"
runat="server"
ImageUrl="~/App_Themes/images/date.png"
/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="Label4145"
runat="server"
ForeColor="Red"
Text="*"></asp:Label>
<asp:Label ID="Label5" runat="server"
Text="Tender
Submission"></asp:Label>
</td>
<td align="left">
<table>
<tr>
<td>
<asp:TextBox ID="txt_TenderSubmission"
runat="server"
Width="80px"
onkeydown="return
false;"
onpaste="return
false;"></asp:TextBox>
</td>
<td>
<asp:ImageButton ID="IB_TenderSubmission"
runat="server"
ImageUrl="~/App_Themes/images/date.png"
/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="Label4146"
runat="server"
ForeColor="Red"
Text="*"></asp:Label>
<asp:Label ID="Label36"
runat="server"
Text="Preferred
Supplier chosen"></asp:Label>
</td>
<td align="left">
<table>
<tr>
<td>
<asp:TextBox ID="txt_PreferredSupplierchosen"
runat="server"
Width="81px"
onkeydown="return
false;"
onpaste="return false;"></asp:TextBox>
</td>
<td>
<asp:ImageButton ID="IB_PreferredSupplierchosen"
runat="server"
ImageUrl="~/App_Themes/images/date.png"
/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right"
colspan="2"
style="text-align: center">
<asp:Button ID="BtnSaveIMPdate" runat="server" Style="height: 26px" Text="Save"
ValidationGroup="vgSave"
Width="80px"
OnClientClick="sendImpDates();
return false;" />
</td>
</tr>
</table>
</div>
SCRIPT
json2.js – Search on google for JSfile
<script src="../App_Themes/MY/json2.js"
type="text/javascript"></script> <%--important --%>
<script type="text/javascript" language="JavaScript">
function sendImpDates() {
vActiveIndex = 2;
var iCount = 0;
var iBidNo = 0;
//debugger;
var items = {};
items.BidNo
= $("#<%=hf_BidNo.ClientID %>").val();
items.RFQIssue
= $("#<%=txt_RFQIssue.ClientID %>").val();
items.ClarificationMeeting
= $("#<%=txt_ClarificationMeeting.ClientID
%>").val();
items.TenderSubmission
= $("#<%=txt_TenderSubmission.ClientID
%>").val();
items.PreferredSupplierchosen
= $("#<%=txt_PreferredSupplierchosen.ClientID
%>").val();
$.ajax({
type: "POST",
url: "frmBidInformation.aspx/Set_OpportunityTimelineDetails",
data: '{items: ' + JSON.stringify(items) + '}',
contentType:
"application/json; charset=utf-8",
dataType: "json",
success: function(data) {
alert(data.d);
}
});
}
</script>
Code Behind
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Web.Security;
public class TimeDetails
{
public string BidNo {
get; set; }
public string
RFQIssue { get; set;
}
public string
ClarificationMeeting { get; set; }
public string
TenderSubmission { get; set; }
public string
PreferredSupplierchosen { get; set; }
}
[WebMethod]
public static string Set_OpportunityTimelineDetails(TimeDetails items)
{
clsFuncctionLib objFunLib = new clsFuncctionLib();
string strMessage;
objFunLib.objCon.Open();
objFunLib.objSqlCmd = new SqlCommand("PROC_UPDATE_DETAILS",
objFunLib.objCon);
objFunLib.objSqlCmd.CommandType = CommandType.StoredProcedure;
objFunLib.objSqlCmd.Parameters.AddWithValue("@vBNo",
items.BidNo);
if (items.RFQIssue != null)
objFunLib.objSqlCmd.Parameters.AddWithValue("@dtRFQIssue",
items.RFQIssue);
else
objFunLib.objSqlCmd.Parameters.AddWithValue("@dtRFQIssue",
null);
objFunLib.objSqlCmd.Parameters.AddWithValue("@dtMeetingClarification",
items.ClarificationMeeting);
objFunLib.objSqlCmd.Parameters.AddWithValue("@dtTendorSubmission",
items.TenderSubmission);
objFunLib.objSqlCmd.Parameters.AddWithValue("@dtPreferedSupplier",
items.PreferredSupplierchosen);
objFunLib.objSqlCmd.Parameters.AddWithValue("@vUserID",
HttpContext.Current.Session["vUserID"].ToString());
try
{
strMessage = objFunLib.objSqlCmd.ExecuteScalar().ToString();
}
catch (Exception
ex)
{
strMessage = ex.Message;
}
if (strMessage == "1")
return "Record
updated successfully";
else
return strMessage;
}
No comments:
Post a Comment