Invoke a Jquery function from a webbrowser - c#

I am trying to get a data from a password protected webpage using webbrowser , which uses a div container with 3 JQuery data fields. The 2nd field depends on the 1st one, and the 3rd one of the 2nd one.I need to set those 3 comboboxes and hit submit in order to get the data I want to scrape. The problem is that once the 1st combobox changes, it invokes a function which populates the 2nd and 3rd boxes. I can't figure out how to invoke this function...
This is how the first combobox looks like:
Select s[DCOM1] Selection1
I managed to set the 1st combobox, however the big problem that I have is to invoke viewStep.onSChanged() , which supposed to populate the 2nd box, I just can't make it work.
The onSChanged function is located in a Jquery js. file
self.onsChanged = function(selectadj) {
self.viewBasicsUpdated = true;
log.debug('onsChanged');
if (self.s) {
self.adjEnabled = false;
self.adj = null;
self.auctionType = 'S';
controller.ds.getadjList(self.s.id, function(response) {
controller.applyUpdates(function() {
self.adjList = response.data;
// Add "Add adj" option (as first in array).
self.adjList.unshift({
id : ADD_adj_ID,
fullName : controller.locale.getMessage('app.label.add.adj')
});
self.adjEnabled = true;
self.standardEnabled = true;
self.vixEnabled = (StringUtils.trimWS(self.s.vixFlag) === 'Y') ? true : false;
self.offsiteEnabled = (StringUtils.trimWS(self.s.offsiteFlag) === 'Y') ? true : false;
self.titOnlyEnabled = (StringUtils.trimWS(self.s.titOnlyFlag) === 'Y') ? true : false;
self.salType = self.s.salType;
self.titProcurementFlag = (StringUtils.trimWS(self.s.titProcurmentFlag) === 'Y') ? true : false;
//Selects the adj when a new adj is added.
if(selectadj){
angular.forEach(self.adjList, function(object, index) {
log.debug("object.id++"+object.id);
if(object.id===self.newadjId){
self.adj=object;
log.debug("self.newadjId++"+object.id);
}
});
}
});
});
}else{
controller.applyUpdates(function() {
self.adj = null;
self.adjEnabled = false;
self.auctionType = 'S';
self.standardEnabled = false;
self.vixEnabled = false;
self.offsiteEnabled = false;
self.titOnlyEnabled = false;
self.salType = null;
self.titProcurementFlag = false;
});`
}
};
I have tried to invoke the function in many different options including invokescript, posting an identical post request as the one I see with Fiddler (I guess it fails since the cookie is different) but everything fails. Is there a way to execute this function?

When setting values on input controls with Javascript the DOM events might not fire, depending on how the values are set.
Instead of trying to execute the very same function that the webpage would normally trigger, in this case self.onsChanged, fire the event on the control that you updated.
$("#selectBox1").val("Value A");
$("#selectBox1").change();
https://api.jquery.com/change/

Related

Data not binded to C# ListView (after second attempt)

I am trying to use a ListView to pull in data from a database. It "works" on the first try if the value exists, but it has a problem when searching for values that don't and then trying again with any other value(even if that other value does exist).
When debugging, I noticed the following:
If I search for a value that doesn't exist in thedatabase, then try to search for one that does, the debugger goes from the line "bValid = true" directly to the method to get the data for the Listview (lstAuthorizations_GetData()). Instead it should go to bindData. It seems like its not processing the bValid = true line. Why would it break here? I've tried changing the line to other variations but no matter what it is, it doesn't seem to process in the right order
Code:
else //default
{
if(string.IsNullOrEmpty(Search_ANumber) && string.IsNullOrEmpty(Search_MemberID))
{
bValid = false;
errorMsg = "Either A Number or M ID are required";
}
else
{
bValid = true;
lstAuthorizations.FindControl("cColumn").Visible = false; // if not in ActiveExceptions, hide column //may want to move this to Line 214
}
}
if (bValid)
{
bindData();
}
protected void bindData()
{
//removeTextBoxValues(); //remove values from Textboxes since you got a response from the DB
ShouldSearch = true;
panelSearchResults.Visible = true;
lstAuthorizations.DataBind();
}
ListView's getdata method:
public IQueryable<Project.Data.databaseView> lstAuthorizations_GetData()
{
try
{
IQueryable<databaseView> query = dbVBA.databaseView.AsQueryable();
if (!String.IsNullOrEmpty(Search_AuthNumber))
{
query = query.Where(m => m.A_Number == Search_ANumber);
}
return query.OrderBy(a=>a.A_Number);
}
aspx:
<asp:ListView ID="lstAuthorizations" runat="server"
ItemPlaceholderID="litPlaceHolder"
ItemType="Project.Data.databaseView" SelectMethod="lstAuthorizations_GetData">
It seems to run the method to get data from the database twice when it actually returns a result (it goes to the lstAuthorizations_GetData() method, then it goes to data bind, then it goes to the lstAuthorizations_GetData() method again). In cases where I try a second value, it goes to the lstAuthorizations_GetData() method, but never goes to bind data.
Anyone know why this is failing?
I had to move hiding/displaying the control AFTER the data was binded. It works now:
if (bValid)
{
bindData();
lstAuthorizations.FindControl("cColumn").Visible = true;

How to retrieve or enable Radio Button based on database value?

When I use textbox they successfully working like this:
padd.txtCustomerName.Text = this.dtvContacts.CurrentRow.Cells[20].Value.ToString();
but how to apply in Radio Button.
padd.rbtLOI.Text = this.dtvContacts.CurrentRow.Cells[5].Value.ToString();
Try like this
if (this.dtvContacts.CurrentRow.Cells[5].Value.ToString() == "LOI")
{
padd.rbtLOI.Checked = true;
}
else
{
padd.rbtConfirmPO.Checked = true;
}

Label value not set on ComboBox's SelectedIndexChanged (only in one case)

This is possibly the strangest (and possibly most simple) error I have come across. I have a ComboBox with 3 items. Based on the selected index I set the visibility of 3 PictureBoxes and a Label's text. The problem is with the latter:
private void myCombo_SelectedIndexChanged(object sender, EventArgs e)
{
switch (myCombo.SelectedIndex)
{
case 0: // basic
pictureBoxBasicCampaign.Visible = true;
pictureBoxApsisCampaign.Visible = false;
pictureBoxPushCampaign.Visible = false;
lblCampaignTypeDescription.Text = "Runs or schedules a campaign that writes the recipient data into a file or another database table.";
break;
case 1: // apsis
pictureBoxBasicCampaign.Visible = false;
pictureBoxApsisCampaign.Visible = true;
pictureBoxPushCampaign.Visible = false;
lblCampaignTypeDescription.Text = "Runs or schedules a campaign that sends a newsletter or SMS message to recipients via APSIS.";
break;
case 2: // push
pictureBoxBasicCampaign.Visible = false;
pictureBoxApsisCampaign.Visible = false;
pictureBoxPushCampaign.Visible = true;
lblCampaignTypeDescription.Text = "Runs or schedules a campaign that sends a push notification to devices running an iOS or Android app.";
break;
}
}
Everything works fine! But my lblCampaignTypeDescription's text is not changed ONLY when SelectedIndex is 0 and I get an empty label. No exception is thrown and my debug traverses over the lblCampaignTypeDescription.Text. But no text. Case 1 and 2 display the text correctly.
Has anyone ever had this issue? Or have I done something stupid?
Update:
All references to lblCampaignTypeDescription in my project:
private MetroFramework.Controls.MetroLabel lblCampaignTypeDescription;
this.lblCampaignTypeDescription = new MetroFramework.Controls.MetroLabel();
this.metroTabPageSelectType.Controls.Add(this.lblCampaignTypeDescription);
//
// lblCampaignTypeDescription
//
this.lblCampaignTypeDescription.FontSize = MetroFramework.MetroLabelSize.Small;
this.lblCampaignTypeDescription.FontWeight = MetroFramework.MetroLabelWeight.Regular;
this.lblCampaignTypeDescription.Location = new System.Drawing.Point(121, 261);
this.lblCampaignTypeDescription.Name = "lblCampaignTypeDescription";
this.lblCampaignTypeDescription.Size = new System.Drawing.Size(700, 18);
this.lblCampaignTypeDescription.Style = MetroFramework.MetroColorStyle.Silver;
this.lblCampaignTypeDescription.TabIndex = 11;
this.lblCampaignTypeDescription.Text = "campaign_type_description";
this.lblCampaignTypeDescription.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lblCampaignTypeDescription.Theme = MetroFramework.MetroThemeStyle.Light;
this.lblCampaignTypeDescription.UseStyleColors = true;
The label is a custom label control from MetroFramework Winform UI library. But I have been using it a million times and this it the first time this is happening.
When your SelectedIndex changes from 1 to 0 or from 2 to 0 does your lblCampaignTypeDescription.Text changes?Try to show the selectedIndex before other actions.It should be -1 i think

Block editing and deletion of rows in KendoUI grid programatically

Using Kendo in an MVC application. I have a grid that shows a few rows. Some are editable, some are not. Some are deletable, some are not.
So, I defined events for this in the MVC Razor layout:
.Events(o => {
o.Edit("onGridEdit");
o.Remove("onGridRemove");
})
Then I defined JavaScript to handle this. My first issue is that the deletion event fires after delete. I need to fire beforehand and prevent it. I also want to prevent the confirmation popup.
The edit event behaves as expected. But it still does not work. Here's what I did:
function onGridEdit(e) {
var grid = $("#grid").data("kendoGrid");
var canEditLine = #(someObj.SomeProperty ? "true" : "false");
if (!canEditLine) {
grid.cancelRow();
alert("You do not have rights to modify this line.");
}
}
The result is that the cell being edited is locked, and the user never sees it opened. The alert fires as expected. The problem is that the entire original row gets rendered inside this column rather than this single column getting updated. Here's a screenshot:
Can anyone help with this? I don't want to cancel all row changes; just the row the user is trying to mess with.
EDIT:
Based on the answer below, here's the updated JavaScript code. The styles and databound events below I used as indicated.
function onUserAssignGridDataBound(e) {
var grid = this;
var canDelete = #(userRights.CanDeleteLockedLines ? "true" : "false");
var canEdit = #(userRights.CanEditLockedLines ? "true" : "false");
grid.tbody.find(">tr").each(function () {
var dataItem = grid.dataItem(this);
if (dataItem) {
if ((dataItem.IsReceived) && (!canDelete)) {
$(this).find(".k-grid-delete").css("visibility", "hidden");
}
if ((dataItem.IsLocked) && (!canEdit)) {
dataItem.fields["Description"].editable = false;
dataItem.fields["Quantity"].editable = false;
dataItem.fields["Price"].editable = false;
}
}
});
}
Hide the remove button bases on grid data on databound event
**********************Grid*******************************
.Events(e => e.DataBound("onUserAssignGridDataBound"))
*************************script****************************
function onUserAssignGridDataBound(e) {
var grid = this;
grid.tbody.find('>tr').each(function () {
var dataItem = grid.dataItem(this);
if (dataItem != null) {
if (dataItem.Role.RoleId != 2) {
$(this).find('.k-plus').addClass('hideCell');
}
}
});
}
****************************Styles CSS**********************
.hideCell {
visibility:hidden;
}
.showCell {
visibility:visible;
}

Remove empty space when visible property is set to false using JavaScript

I'm having a DropdownList and when its Selected Value is changed (for ex: 0 ) I need to set the visible property of a Panel to True and the visible property of another Panel to False.
and when another Value is selected I need to do Vice Versa Using JAVASCRIPT.
I'm currently achieving this but the space remains as it is. How can i remove the spaces also.
can anyone help me??
I'm attaching the code also.
function visible(val) {
var ddl = document.getElementById("ddl_IDProof");
var selectedFilterType = drpFilterType.options[ddl.selectedIndex].value;
if (selectedFilterType == "0") {
document.getElementById("pnl1").style.visibility = "visible";
document.getElementById("pnl2").style.visibility = "hidden";
}
else {
document.getElementById("pnl1").style.visibility = "hidden";
document.getElementById("pnl2").style.visibility = "visible";
}
}
Use display instead of visibility.
This will hide the entire element:
// Show pnl1 (maybe you have to use inline or inline-block insdead of block)
document.getElementById("pnl1").style.display = "block";
// Hide pnl2
document.getElementById("pnl2").style.display = "none";

Categories

Resources