Friday, June 17, 2016

update controls outside updatepanel c#

In this article, I am going to explain how to update Control value or any other ASP. net control which reside out side update panel.

Let's take a example, suppose I have a button inside update panel and click on that button I want to assign some value in textbox.

Here the aspx Code

<%@ 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">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scmain" runat="server"></asp:ScriptManager>
 
    <asp:UpdatePanel ID="upmain" runat="server">
    <ContentTemplate>
     <fieldset>
    <legend>Button Inside Update Panel</legend>
    <asp:Button ID="btnUpdateValue" runat="server" Text="UpdateValue"
             onclick="btnUpdateValue_Click" />
    </fieldset>
    </ContentTemplate>
    </asp:UpdatePanel>
 
     <asp:UpdatePanel ID="uptextbox" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <fieldset>
    <legend>Out Side TextBox of Update Panal</legend>
    <asp:TextBox ID="txtvalue" runat="server"></asp:TextBox>
    </fieldset>
    </ContentTemplate>
    </asp:UpdatePanel>
 
    </form>
</body>
</html>

Here the aspx.cs Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void btnUpdateValue_Click(object sender, EventArgs e)
    {
        txtvalue.Text = "Verified";
        uptextbox.Update();
    }
}

Output




No comments:

Post a Comment