Here is the our aspx page that contains a JavaScript
method and a hidden filed and button.
<script
type="text/javascript">
function SetValue() {
var sValue = "Hello
World";
document.getElementById("Hidden1").value
= str;
}
</script>
<html>
<head>
<title>How to set c# variable value
in javascript</title>
</head>
<body>
<div>
<asp:hiddenfield id="hdnVlaue" runat="server"></asp:hiddenfield>
<asp:button id="btnClick" runat="server"
onclientclick="SetValue()" onclick="”" text="Click
Me"> </asp:button>
</div>
</body>
</html>
Now in the click event of the btnClick, we will set value
received by JavaScript function
protected void btnClick_Click(object sender, EventArgs e)
{
string sValue = hdnVlaue.Value;
Response.Write("The
Received Value is " + sValue);
}
using System;
using System.Net.Mail;
using System.Net.Security;
public partial class SendEmailPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MailMessage oMailMessage = new MailMessage("Your Email Address
", "Recepent’s
Email Address ");
oMailMessage.Subject = "Write Your Mail Here";
oMailMessage.Body = "Write Your Email Message";
oMailMessage.IsBodyHtml = false;
SmtpClient oSmtpClient = new SmtpClient("smtp.gmail.com", 587);
oSmtpClient.Credentials = new System.Net.NetworkCredential("Email Username", "Email Password");
oSmtpClient.EnableSsl = true;
oSmtpClient.Send(oMailMessage);
}
}
using System;
using System.Web;
using System.Web.UI;
public partial class GetDeviceType : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void OnInit(EventArgs e)
{
string sUserAgent = Request.UserAgent.ToLower();
if (sUserAgent.Contains("tablet"))
{
this.MasterPageFile = "/Tablet.master";
}
else
{
this.MasterPageFile = "/Mobile.master";
}
}
}
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
public partial class AddMetaTageProgrammatically : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Adding Title
Page.Title = "How to add meta tags
programmatically.";
//Adding Meta Descriptions
HtmlMeta oHtmlMetaDescription = new HtmlMeta();
oHtmlMetaDescription.Name = "description";
oHtmlMetaDescription.Content = "How to add meta tags
programmatically in asp.net with c#.";
Page.Header.Controls.Add(oHtmlMetaDescription);
oHtmlMetaDescription = null;
//Adding Meta Keywords
HtmlMeta oHtmlMetaKeywords = new HtmlMeta();
oHtmlMetaKeywords.Name = "keywords";
oHtmlMetaKeywords.Content = "meta tags, adding meta
tags programmatically, meta tags in asp.net";
Page.Header.Controls.Add(oHtmlMetaKeywords);
oHtmlMetaKeywords = null;
}
}
SqlCommand cmd;
SqlConnection con;
SqlDataAdapter da;
DataSet ds;
private void button1_Click(object sender, EventArgs e)
{
con = new SqlConnection("your_database_connection_sting");
cmd =new SqlCommand ("select * from emp", con);
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
comboBox1.Items.Add(ds.Tables[0].Rows[i][0] + " " + ds.Tables[0].Rows[i][1] + " " + ds.Tables[0].Rows[i][2]);
}
}
SqlConnection con;
SqlDataAdapter da;
DataSet ds;
private void button1_Click(object sender, EventArgs e)
{
con = new SqlConnection("your_database_connection_sting");
cmd =new SqlCommand ("select * from emp", con);
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
comboBox1.Items.Add(ds.Tables[0].Rows[i][0] + " " + ds.Tables[0].Rows[i][1] + " " + ds.Tables[0].Rows[i][2]);
}
}

