How to handle the mouse wheel button event in ASP.NET? - c#

I have a project which uses EXT.NET framework for the controls. I'm currently working on the behavior of closing the panel tabs such as Google Chrome and all the modern browsers does.
I couldn't find the answer to this. What is the ASCII value for the mouse scroll wheel button? How can I handle this event in C# ASP.NET?

working on Firefox, Explorer and Chrome:
$(document).ready(function() {
$(document).mousedown(function(e) {
closeTab(e);
});
});
function closeTab(e) {
if (!e) {
e = window.event;
e.which = e.keyCode;
}
if(e.which == 2){
var tbpPrincipal = <%= tbpPrincipal.ClientID %>;
var activeTab = null;
for (var i = 0; i < tbpPrincipal.items.length; i++) {
var currentTab = tbpPrincipal.items.items[i];
if (e.target.innerText == currentTab.title || e.target.textContent == currentTab.title) {
activeTab = currentTab;
break;
}
}
if (activeTab) {
var activeTabIndex = tbpPrincipal.items.findIndex('id', activeTab.id);
tbpPrincipal.remove(activeTabIndex);
}
}
return true;// to allow the browser to know that we handled it.
}

Related

Checkbox group not detecting if checked

So I am recieving some postback data back from a form and need to get the checkbox values for a group of checkboxes in a parent control. I coded it up and it was working but now no longer works and I can not figure out why. The checkboxes are created on page load dynamically but on postback nothing seems to be checked when the form had checked items, the only postback event is the submit button event.
// This is from the btnSubmit Postback event that isn't working anymore
foreach (CheckBox cb in ShowPermissions.Controls.OfType<CheckBox>())
{
if (cb.Checked)
{
// Add New Admins Permissions
Permission p = new Permission();
p.AdminUserID = au.id;
p.AdminMenuID = Convert.ToInt32(cb.ID.ToString().Substring(4));
ngdb.Permissions.InsertOnSubmit(p);
submitResult.InnerHtml += cb.ID.ToString();
// Does not run now?
}
// can see the checkbox object
}
protected void Page_Load(object sender, EventArgs e)
{
FunctionType = Request.QueryString["func"] != null && Request.QueryString["func"] != "" ? Request.QueryString["func"] : null;
RID = Request.QueryString["rid"] != null && Request.QueryString["rid"] != "" ? int.Parse(Request.QueryString["rid"]) : -1;
PopulateAdminTypes();
if (!IsPostBack && FunctionType == "edit" && RID != -1)
{
// Populate User details for Edit
PopulateUser(RID);
// Populate checkboxes and check selected options
PopulateAdminPermissionOptions(true, RID);
// Disable password change
ChangePassword(false);
}
else if (!IsPostBack)
{
chkChangePassword.Visible = false;
PopulateAdminPermissionOptions(false, -1);
}
}
private void PopulateAdminPermissionOptions(bool blnPopulateForEdit, int RID)
{
// Get Logged in Admin ID
int intAdminId = Convert.ToInt32(Session["AdminID"]);
int intAdminTypeId = Convert.ToInt32(Session["AdminTypeID"]);
using (NewGeorgeDataContext ngdb = new NewGeorgeDataContext())
{
var am = ngdb.AdminMenus.AsQueryable();
// Hide Add and Edit Options from Non Super Users
var amUsers = ngdb.AdminMenus.Where(x => x.id > 2 && x.id < 5);
if (intAdminTypeId > 1) am = am.Except(amUsers);
foreach (var m in am.OrderBy(x => x.MenuTypeID).ThenBy(x => x.id))
{
// Add New CheckBox
CheckBox cb = new CheckBox();
cb.ID = "chk_" + m.id;
cb.CssClass = "chkItems";
cb.Text = m.AdminMenuType.Name + ": " + m.Name;
// Get Admin Permission objects
if (blnPopulateForEdit)
{
var ap = ngdb.Permissions.SingleOrDefault(x => x.AdminUserID == RID && x.AdminMenuID == m.id);
if (ap != null)
{
cb.Checked = true;
}
}
ShowPermissions.Controls.Add(new LiteralControl("<p>"));
ShowPermissions.Controls.Add(cb);
ShowPermissions.Controls.Add(new LiteralControl("</p>"));
}
}
}
Can someone workout what I cannot see atm?
The view state isn't getting load into your controls. You must create all the controls before LoadViewState triggers. So, create all dynamic Controls OnPageInit event or Page_Init method to get the correct behavior. Take a look here to get more information about Asp.NET Page Life Cycle
Hopes this help you!

.net listbox trigger event on select from javascript

when I am trying to trigger an event on select from listbox asp.net user control in ie 7 8 9
$("select").trigger("change")
$("select").trigger(jQuery.Event("change", {target: $("select").get(0)}));
$("select").trigger(jQuery.Event("change", {srcElement: $("select").get(0)}));
predefined .net script fails in the predefined function that no one can change
function ValidatorOnChange(event) {
if (!event) {
event = window.event;
}
Page_InvalidControlToBeFocused = null;
var targetedControl;
if ((typeof(event.srcElement) != "undefined") && (event.srcElement != null)) {
targetedControl = event.srcElement;
}
else {
targetedControl = event.target;
}
var vals;
if (typeof(targetedControl.Validators) != "undefined") {
vals = targetedControl.Validators;
}
else {
if (targetedControl.tagName.toLowerCase() == "label") {
targetedControl = document.getElementById(targetedControl.htmlFor);
vals = targetedControl.Validators;
}
}
var i;
for (i = 0; i < vals.length; i++) {
ValidatorValidate(vals[i], null, event);
}
ValidatorUpdateIsValid();
}
because event is suddenly null it cannot find event.target.Validators or event.srcElement.Validators. How to trigger change event properly?
You should be able to trigger with $("select").change(); and handle the event with $("select").change(function(){ //code here });
during .net generated script investigation I have over 9000 facepalm per second.
I think that if you are noob you should learn before write something. but over 9000 microsoft's indians doesn't think so
var original_trigger = $.fn.trigger;
$.fn.trigger = function(type, data) {
if($.browser.msie) {
$(this).each(function() {
window.ValidatorOnChange({
target: this
});
});
return $(this).trigger("CustomChange", data);
}
return original_trigger.apply(this, arguments);
}
this is bad too. the best way is to list change listeners, remove indian's ValidatorOnChange listener and rebind it properly. but unfortunately i have no many time to delve into this sh*t

CheckBox inside ListView control using ASP.Net 3.5

When CheckBox is unchecked in a ListView i need to get a popup window?
I have make a JS function and just pass id of your list like as
OnClientClick="return GetSelectedCheckBoxInGrid('grdCustomer');"
function GetSelectedCheckBoxInGrid(obj)
{
var con = 'ctl00_ContentPlaceHolder1_' + obj
var Parent = document.getElementById(con);
var TargetChildControl = "chk";
if (Parent==null)
{
return false;
}
var items = Parent.getElementsByTagName("input");
for(var n = 0; n < items.length; ++n)
if(items[n].type == 'checkbox' &&
items[n].id.indexOf(TargetChildControl,0) >= 0 &&
items[n].checked == false)
alert('Hi');return false;)
}
I think this is that
Not too sure about this, but hypothetically, you could give each checkbox a class, eg chkbox, and then have some jquery code to handle a click event:
$('chkbox').click(function() {
alert("here is where you put your popup code");
});
You could use window.open here
$('chkbox').click(function() {
if (! $('#chkbox').is(':checked'))
{
window.open ("http://www.javascript-coder.com","mywindow","status=1");
}
});
or
$('chkbox').click(function() {
if(! $('#chkbox').attr('checked'))
{
window.open ("http://www.javascript-coder.com","mywindow","status=1");
}
});
How to check whether a checkbox is checked in jQuery?

Clear asp.net form at runtime

Whats the easiest way to clear an asp.net form at runtime using c#.
Thanks
Sp
I assume you want to clear input boxes, dropdowns etc. This can be done the following way in code to recursivly clear all data.
foreach( var control in this.Controls )
{
ClearControl( control );
}
and the recursive function
private void ClearControl( Control control )
{
var textbox = control as TextBox;
if (textbox != null)
textbox.Text = string.Empty;
var dropDownList = control as DropDownList;
if (dropDownList != null)
dropDownList.SelectedIndex = 0;
// handle any other control //
foreach( Control childControl in control.Controls )
{
ClearControl( childControl );
}
}
I have used the following JS/c# to clear the form.
c# to add the js call onload
Page.ClientScript.RegisterStartupScript(typeof(WebForm3), "ClearPage", "ClearForm();", true);
the JS to clear the form
function ClearForm() {
var AllControls = document.getElementById('ctl00_ContentPlaceHolder1_PnlAll')
var Inputs = AllControls.getElementsByTagName('input');
for (var y = 0; y < Inputs.length; y++) {
// define element type
type = Inputs[y].type
// alert before erasing form element
//alert('form='+x+' element='+y+' type='+type);
// switch on element type
switch (type) {
case "text":
case "textarea":
case "password":
//case "hidden":
Inputs[y].value = "";
break;
}
}
}

Text box content rendering in a new window using javascript

I have a asp.net textbox(textarea which is in a repeater have single texarea for each record which are read only) I have button (open in new window) when i click on it the content of the text area needs to be rendered in a new window using javascript .
similar to experts exchange.
Sorry I misread the question the first time.
Here is a javascript solution:
function DisplayTextFromRepeater()
{
var text = '';
var repeater = document.getElementById('MyRepeater');
var inputs = repeater.getElementsById('input');
var txtId = 'MyTextBox' //ID of textbox in repeater template
for(var i = 0; i < inputs.length; i++)
{
if(inputs[i].type == 'text')
{
if(inputs[i].id.indexOf(txtId) != -1)
{
text = text + inputs[i].value;
}
}
}
OpenNewWindow(text);
}
function OpenNewWindow(message)
{
var OpenWindow = window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars=yes,menubar=no");
OpenWindow.document.write("<html>");
OpenWindow.document.write("<title>Title Goes Here</title>");
OpenWindow.document.write("<body>");
OpenWindow.document.write(message);
OpenWindow.document.write("</body>");
OpenWindow.document.write("</html>");
}

Categories