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...
Subscribe to:
Posts (Atom)