Wednesday 9 October 2013

how to Fetch data from .aspx page to .cs or .vb page using javascript | Attribute.Add | Gridview_RowCommand |

In this article  I have shown how to retrieve or fetch data or value from .aspx page to .cs or .vb page .
I have used here c#. now there is two method to   fetch .aspx value from .aspx page to .cs page.
How to use Confirm box in asp.net.
1->Ajax
2->Javascript.
3-Javascript with Attribute.Add Property.
Now suppose i want to display confirm box and after that if user is saying
or clicking yes then execute function else  exit.
In here .cs page i have tried same functionality with GridView_rowcommand event.
suppose user want to delete clicked row from table or we can say grid.
what he will do, firstly he will click on delete link button  , actually i have taken linkbutton into the grid.
after clicking delete link button Confirm Box will appear (poped up)
then according to yes or cancel selection function will be execute.
consider user  has clicked delete link button then ..
((LinkButton)(row.FindControl("lnkbtndel"))).Attributes.Add("onclick", "javascript:return GetConfirmval();");

GetConfirmval() function will be called which is javascript function .
now comes to javascript..


 <script type ="text/javascript" >
    function GetConfirmval()
    {
    var value;
var val=confirm ("Are you sure want to delete selected record ");
   if (val==true )
   {
   document .getElementById ('<%=hdnEditdel.ClientID%>').value=1;
   }
    else
    {
    document .getElementById ('<%=hdnEditdel.ClientID%>').value=2;
    }
   
    }
    </script>

what i did here is , taken one hiddenfield  and assigned  different values according to requirement.
what happens when user click on yes on confirm box hiddenfield values will be set 1.
else 2.

now this  value we will use  .cs page .


protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       LinkButton lnkbtn = (LinkButton)e.CommandSource ;
           GridViewRow row = (GridViewRow)lnkbtn.NamingContainer;

if (hdnEditdel.Value==Convert.ToString ("1")) // if value 1 means user clicked yes on confirm box.
           {

               Response.Write("1");

               DataTable dt = (DataTable)(ViewState["NewFirstTable"]);//stored data
               dt.Rows.RemoveAt(row.RowIndex);
               GridView1.DataSource = dt;
               GridView1.DataBind();
           }
           else
           {
               Response.Write("2");

           }
           hdnEditdel.Value = "";
}


now here is one way but in this method user need to click twice on link button which i have already used on gridview.
so to avoid that issue what i did i just took  OnlientClick  event and  call javascript function over there.
because that is perfect.
<asp:LinkButton runat="server" ID="lnkbtndel" Text ="Delete" CommandName ="Del" OnClientClick ="return GetConfirmval()"></asp:LinkButton>
step->
1->To use attribute remove onclient click on link button .
2->To use onclient click remove attribute from  rowcommand.


Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: