Hi taruni,
Check this example. Now please take its reference and correct your code.
HTML
<asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="Btnformsubmit_Click" Style="display: none;" />
<div id="dvPopup" style="display: none;">
<asp:TextBox runat="server" ID="txtId" /><br />
<asp:TextBox runat="server" ID="txtName" /><br />
<asp:TextBox runat="server" ID="txtCountry" />
</div>
<script type="text/javascript">
function PopulateTextBox(id, name, country) {
document.getElementById('txtId').value = id;
document.getElementById('txtName').value = name;
document.getElementById('txtCountry').value = country;
}
function ShowPopup() {
document.getElementById('dvPopup').style.display = "block";
}
</script>
Namespaces
C#
using System.Data;
using System.Text;
VB.Net
Imports System.Data
Imports System.Text
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3]
{
new DataColumn("Id"),
new DataColumn("Name"),
new DataColumn("Country")
});
dt.Rows.Add(1, "Mudassar Khan", "India");
if (dt.Rows.Count > 0)
{
string id = dt.Rows[0]["Id"].ToString();
string name = dt.Rows[0]["Name"].ToString();
string country = dt.Rows[0]["Country"].ToString();
StringBuilder sb = new StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("PopulateTextBox('" + id + "','" + name + "','" + country + "');");
sb.Append("ShowPopup();");
sb.Append("document.getElementById('btnSubmit').click();");
sb.Append("};");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "message", sb.ToString());
}
}
}
protected void Btnformsubmit_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "message", "alert('Button clicked.')", true);
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(2) {
New DataColumn("Id"),
New DataColumn("Name"),
New DataColumn("Country")})
dt.Rows.Add(1, "Mudassar Khan", "India")
If dt.Rows.Count > 0 Then
Dim id As String = dt.Rows(0)("Id").ToString()
Dim name As String = dt.Rows(0)("Name").ToString()
Dim country As String = dt.Rows(0)("Country").ToString()
Dim sb As StringBuilder = New StringBuilder()
sb.Append("<script type = 'text/javascript'>")
sb.Append("window.onload=function(){")
sb.Append("PopulateTextBox('" & id & "','" & name & "','" & country & "');")
sb.Append("ShowPopup();")
sb.Append("document.getElementById('btnSubmit').click();")
sb.Append("};")
sb.Append("</script>")
ClientScript.RegisterStartupScript(Me.GetType(), "message", sb.ToString())
End If
End If
End Sub
Protected Sub Btnformsubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
ClientScript.RegisterStartupScript(Me.GetType(), "message", "alert('Button clicked.')", True)
End Sub