Showing posts from May, 2015

ASP.NET Get radio button value in javascript

Radio button html

<input type="radio" name="mxCard" id="mxcard" data-id="<%=mxcard.MxFormaterCreditCard%>" value="<%=mxcard.MxFormaterCreditCard%>" />

get radio button value in java script

var selectedVal = ""; var selected = $('input[type=radio][name=mxCard]:checked').val(); if (selected) { // Do something } }

Detect browser language and other information in ASP.NET

If you just want to detect browser language you can use this

CultureInfo ci; if (userLanguages.Count() > 0) { try { ci = new CultureInfo(userLanguages[0]); } catch (CultureNotFoundException) { ci = CultureInfo.InvariantCulture; } } else { ci = CultureInfo.InvariantCulture; }
if you want to get more details then use this

string browser = HttpContext.Request.Browser.Browser; string version = HttpContext.Request.Browser.Version; string type = HttpContext.Request.Browser.Type; string platform = HttpContext.Request.Browser.Platform; string userAgent = HttpContext.Request.UserAgent; string[] userLang = HttpContext.Request.UserLanguages; var userLanguages = Request.UserLanguages;

For MVC use this in your Home controller action.

Session value show in html ASP.NET

Set the value:

HttpContext.Current.Session["CVVAndOTPRequiredCardMessage"] = cardNoMessage; HttpContext.Current.Session["CVVAndOTPRequiredCardMessage2"] = cardNoMessage2;
Show session value in html:

<p> <%=Server.HtmlEncode(HttpContext.Current.Session["CVVAndOTPRequiredCardMessage"].ToString())%></br> <%=Server.HtmlEncode(HttpContext.Current.Session["CVVAndOTPRequiredCardMessage2"].ToString())%> </p>