ASP.net, c#.net, sql Server 2005-2008, html, javascript, Cristal Reports, ADO.net, Ajax, xml, MVC, Jquery, JSON, WebServices, WCF, Web API, etc.........
Wednesday, January 25, 2012
Tuesday, January 17, 2012
Detecting browser refresh or F5 click on page in c#
Friends,
I found an interesting problem in my application.
after saving data in database I clear the page and reset all control at the page. but If I click on browser refresh or press F5 on keyboard, Page get post back and save/ update or button click execute again with old values which were exists just before reset data.
So now the records or operation process again which is wrong in my condition and I do not want to process that code again.
I search a lot over Internet for the solution of the above problem and after a lot of findings I found a working solution for me.
So I am going to explain the solution for the convenience of the other developers
I found an interesting problem in my application.
after saving data in database I clear the page and reset all control at the page. but If I click on browser refresh or press F5 on keyboard, Page get post back and save/ update or button click execute again with old values which were exists just before reset data.
So now the records or operation process again which is wrong in my condition and I do not want to process that code again.
I search a lot over Internet for the solution of the above problem and after a lot of findings I found a working solution for me.
So I am going to explain the solution for the convenience of the other developers
#region code to determine Refresh state of Page ie. button click or F5 hit
private bool _refreshState; private bool _isRefresh;
protected override void LoadViewState(object savedState)
{
object[] AllStates = (object[])savedState;
base.LoadViewState(AllStates[0]);
_refreshState = bool.Parse(AllStates[1].ToString());
_isRefresh = _refreshState == bool.Parse(Session["__ISREFRESH"].ToString());
}
protected override object SaveViewState()
{
Session["__ISREFRESH"] = _refreshState;
object[] AllStates = new object[2];
AllStates[0] = base.SaveViewState();
AllStates[1] = !(_refreshState);
return AllStates;
}
#endregion
protected void imgbtnSave_Click(object sender, ImageClickEventArgs e)
{
try
{
if (!_isRefresh)
{
// your code goes here
}
}
}
private bool _refreshState; private bool _isRefresh;
protected override void LoadViewState(object savedState)
{
object[] AllStates = (object[])savedState;
base.LoadViewState(AllStates[0]);
_refreshState = bool.Parse(AllStates[1].ToString());
_isRefresh = _refreshState == bool.Parse(Session["__ISREFRESH"].ToString());
}
protected override object SaveViewState()
{
Session["__ISREFRESH"] = _refreshState;
object[] AllStates = new object[2];
AllStates[0] = base.SaveViewState();
AllStates[1] = !(_refreshState);
return AllStates;
}
#endregion
protected void imgbtnSave_Click(object sender, ImageClickEventArgs e)
{
try
{
if (!_isRefresh)
{
// your code goes here
}
}
}
if _isRefresh variable is true then user refresh the browser or click F5
hope this code helps you.....................
Thursday, January 12, 2012
INSERT ROW FROM ONE TABLE TO ANOTHER
Hello Friends,
below written query describes us how to insert Data From One table to another in same Schema Database in oracle
below written query describes us how to insert Data From One table to another in same Schema Database in oracle
INSERT INTO TX_ITEM_IR_TRN_SUB
(
(
-- provide all column here of table i.e. TX_ITEM_IR_TRN_SUB
SELECT T.YEAR,
T.COMP_CODE,
T.BRANCH_CODE,
T.TRN_TYPE,
T.TRN_NUMB,
T.PO_COMP_CODE,
T.PO_BRANCH,
T.PO_TYPE,
T.PO_NUMB,
T.ITEM_CODE,
T.TRN_QTY,
0,
'UnChecked',
'NA',
'NA',
SYSDATE,
'AKHILESH',
T.TDATE,
'0',
T.NO_OF_UNIT,
T.UOM_OF_UNIT,
T.WEIGHT_OF_UNIT
FROM TX_ITEM_IR_TRN T
WHERE SUBSTR (T.TRN_TYPE, 1, 1) = 'R'
AND (T.YEAR,
T.COMP_CODE,
T.BRANCH_CODE,
T.TRN_TYPE,
T.TRN_NUMB,
T.PO_COMP_CODE,
T.PO_BRANCH,
T.PO_TYPE,
T.PO_NUMB,
T.ITEM_CODE) NOT IN
(SELECT YEAR,
COMP_CODE,
BRANCH_CODE,
TRN_TYPE,
TRN_NUMB,
PO_COMP_CODE,
PO_BRANCH,
PO_TYPE,
PO_NUMB,
ITEM_CODE
FROM TX_ITEM_IR_TRN_SUB));
T.COMP_CODE,
T.BRANCH_CODE,
T.TRN_TYPE,
T.TRN_NUMB,
T.PO_COMP_CODE,
T.PO_BRANCH,
T.PO_TYPE,
T.PO_NUMB,
T.ITEM_CODE,
T.TRN_QTY,
0,
'UnChecked',
'NA',
'NA',
SYSDATE,
'AKHILESH',
T.TDATE,
'0',
T.NO_OF_UNIT,
T.UOM_OF_UNIT,
T.WEIGHT_OF_UNIT
FROM TX_ITEM_IR_TRN T
WHERE SUBSTR (T.TRN_TYPE, 1, 1) = 'R'
AND (T.YEAR,
T.COMP_CODE,
T.BRANCH_CODE,
T.TRN_TYPE,
T.TRN_NUMB,
T.PO_COMP_CODE,
T.PO_BRANCH,
T.PO_TYPE,
T.PO_NUMB,
T.ITEM_CODE) NOT IN
(SELECT YEAR,
COMP_CODE,
BRANCH_CODE,
TRN_TYPE,
TRN_NUMB,
PO_COMP_CODE,
PO_BRANCH,
PO_TYPE,
PO_NUMB,
ITEM_CODE
FROM TX_ITEM_IR_TRN_SUB));
How to find Current GridViewRow in TextBox text change event
Hello Friends,
Now I am going to explain to find a GridViewRow in TextBox TextChanged Event inside GridView
Some times we had a TextBox or CheckBox or any other control inside GridView and we have to find the GridViewRow when the TextChanged or CheckedChanged or concerned Event fires
The following code show us how to do that
in same way you can find gridview in any event inside gridview
}
Now I am going to explain to find a GridViewRow in TextBox TextChanged Event inside GridView
Some times we had a TextBox or CheckBox or any other control inside GridView and we have to find the GridViewRow when the TextChanged or CheckedChanged or concerned Event fires
The following code show us how to do that
protected void txtTest_TextChanged(object sender, EventArgs e)
{
{
// code to find text box
TextBox txtTextBox = ((TextBox)(sender));
TextBox txtTextBox = ((TextBox)(sender));
// code to find GridViewRow using naming container (bubble Event)
GridViewRow grdRow = ((GridViewRow)(txtTextBox.NamingContainer));
GridViewRow grdRow = ((GridViewRow)(txtTextBox.NamingContainer));
// code to find Label inside GridViewRow
Label lblTest = grdRow .FindControl("lblTest") as Label;
Label lblTest = grdRow .FindControl("lblTest") as Label;
}
in same way you can find gridview in any event inside gridview
protected void chkApproved_CheckedChanged(object sender, EventArgs e)
{
try
{
CheckBox chk = ((CheckBox)(sender));
GridViewRow gv1 = ((GridViewRow)(chk.NamingContainer));
}
{
try
{
CheckBox chk = ((CheckBox)(sender));
GridViewRow gv1 = ((GridViewRow)(chk.NamingContainer));
}
catch (Exception ex)
{
// handle your exception
}{
// handle your exception
}
Finding DataListItem in ItemCommand Event of DataList
Dear Friends,
In this post I am going to show how to get the DataLIstItem in ItemCommand Event of a DataList
Here is code for this purpose
In this code, if the command name is FindPersonDetail then I find DataLIstItem of Datalist of the selected Item using Bubble Event. then I find My Label using that DatalistItem.
You can bypass if condition if you not require that.
Hope this code help you...
In this post I am going to show how to get the DataLIstItem in ItemCommand Event of a DataList
Here is code for this purpose
protected void dlTest_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "FindPersonDetail")
{
DataListItem dlItem = (DataListItem)((Control)e.CommandSource).Parent;
string Empname = ((Label)(item.Controls[1].FindControl("lblEmpName"))).Text;
}
{
if (e.CommandName == "FindPersonDetail")
{
DataListItem dlItem = (DataListItem)((Control)e.CommandSource).Parent;
string Empname = ((Label)(item.Controls[1].FindControl("lblEmpName"))).Text;
}
In this code, if the command name is FindPersonDetail then I find DataLIstItem of Datalist of the selected Item using Bubble Event. then I find My Label using that DatalistItem.
You can bypass if condition if you not require that.
Hope this code help you...
Wednesday, January 11, 2012
return a table from Function in Oracle
Hello Guys,
Today I am going to explain how to write a function in oracle which return a table as result set.
We have to follow 3 steps to do so.
Step 1: We are going to create a object type that contains the fields that are going to be returned from function.
Step 2: Now we create a nested table type from above Type
execute this statement
Step 3: So It's time to do our real work i.e. create a function
execute this function.
Now your function is ready and you can call it as shoen below
select * from table( fn_get_emp_salary(2012,25))
I call the function by sending parameter year as 2012 and id as 25
Hope this post help you in writing function in oracle.........
Today I am going to explain how to write a function in oracle which return a table as result set.
We have to follow 3 steps to do so.
Step 1: We are going to create a object type that contains the fields that are going to be returned from function.
CREATE OR REPLACE TYPE emp_type as object
(
id number,
name varchar2(30),
designation varchar2(50),
salary number(16,4)
);
/
execute this statement Step 2: Now we create a nested table type from above Type
CREATE OR REPLACE TYPE emp_type_Table as table of emp_type;
execute this statement
Step 3: So It's time to do our real work i.e. create a function
CREATE OR REPLACE FUNCTION fn_get_emp_salary (Pyear IN number,
P id IN number)
RETURN emp_type_Table
AS
v_ret emp_type_Table ;
BEGIN
SELECT CAST (
MULTISET(
P id IN number)
RETURN emp_type_Table
AS
v_ret emp_type_Table ;
BEGIN
SELECT CAST (
MULTISET(
-- your query goes here
select id, name, designation, salary from emp
where id=Pid and year=Pyear
)
INTO v_ret
FROM DUAL;
RETURN v_ret;
END fn_get_emp_salary ;
/
)
INTO v_ret
FROM DUAL;
RETURN v_ret;
END fn_get_emp_salary ;
/
execute this function.
Now your function is ready and you can call it as shoen below
select * from table( fn_get_emp_salary(2012,25))
I call the function by sending parameter year as 2012 and id as 25
Hope this post help you in writing function in oracle.........
Subscribe to:
Posts (Atom)