I have a webBrowser control on my C# forms app,which works perfectly.
However, the url I am navigating to has JavaScript popups with text on them during interaction.
How do I capture the text on the JavaScript popup boxes?
For example, the alert says "no more food" I want to capture the text "no more food" and pass to a label .
below is my click event code and OnDocumentCompleted event handler
private void iTalk_Button_21_Click(object sender, EventArgs e) //click event
{
Username = username.Text.Trim();
Password=password.Text.Trim();
webBrowser1.Navigate("someurl");
webBrowser1.DocumentCompleted += WebBrowser1_DocumentCompleted;
//MessageBox.Show(Username);
}
private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
tabControl1.SelectedTab = tabPage2;
HtmlDocument doc = this.webBrowser1.Document;
doc.GetElementById("ctl00_MainContent_Login1_UserName").SetAttribute("Value", Username);
doc.GetElementById("ctl00_MainContent_Login1_Password").SetAttribute("Value", Password);
doc.GetElementById("ctl00_MainContent_Login1_LoginButton").InvokeMember("click");
}
Related
Tried Google but couldn't find my answer, So posting it here.
SS is attached in last. When the user clicks on download button, some actions performed on backend i.e. file transfer and when the process is completed, it changes the label text of "Total"
I want to change the label text of the div.
I have tried "RegisterStartupScript" also in place of "RegisterClientScriptBlock"
But didn't work
Tried by setting innerHtml from c# also didn't work
C#
protected void btnrepeat()
{
//my code for load balancing
Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript21211", "UpdateServerMax('" + server1max + "')", true);
//LabelServer1Max.InnerHtml = server1max.ToString();
}
JavaScript
function UpdateServerMax(server1Max) {
alert("njk");
LabelServer1Max.innerHTML = server1Max;
}
HTML
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count" style="margin-bottom: -1%">
<br />
<span class="count_top"><i class="fa fa-user"></i>Total </span>
<div class="count" id="LabelServer1Max" runat="server">
4,567</div>
</div>
Also tried removing runat="server" from div.
Here is the SS what i want to change. https://ibb.co/kZ2Zvk
The 4th label says "Total".
You can update the value from C# after the Page_Load event.It can be somethig like this
protected void Page_Load(object sender, EventArgs e)
{
LabelServer1Max.Text= server1Max;
}
or after the Page_LoadComplete Event
void Page_LoadComplete(object sender, EventArgs e)
{
LabelServer1Max.Text= server1Max;
}
Add it to your .cs file.
my asp project has a asp button which named 'Save'. However, i need to change it to 'Update' in jQuery to do other thing in one button.
The problem is the C# onclick code is still read it as Save..
Code:
//Main
<asp:Button ID="btnSubmit" runat="server" Text="Save" />
//JQuery
$("#<%=btnSubmit.ClientID %>").val("Update");
//C#
var button = sender as Button;
var buttonName = button.Text; //Save
Update1
Question is:
I need to change the button name in JQuery
$("#<%=btnChangeName.ClientID %>").click({
$("#<%=btnSubmit.ClientID %>").val("Update"); //Change Save to Update
});
Then use it in C#:
protected void btnSubmit_Click(object sender, EventArgs e)
{
var button = sender as Button;
var buttonName = button.Text;
if (buttonName == "Save")
{//something}
else
{//something}
}
if you want to change the Name to Update1 in Jquery
try like this
$("#<%=btnSubmit.ClientID%>").val('Update');
Event you neeed to use is OnClientClick
Usage example
OnClientClick="onupd();return false;"
Update
Decalre a Hidden FIeld
<asp:HiddenField runat="server" ID="hdntest" Value="0" />
assign the button change value to update and assign it to the hidden field
not access that hidden value in your code behind.
you can assign Button value to Hidden Field like this
$("#<%=btnSubmit.ClientID %>").val("Update");
$("#<%=hdntest.ClientID%>").val($("#<%=btnSubmit.ClientID%>").attr("value"));
If you change the Button.Click value, then it will move to a different method onClick;
private void Form1_Load(object sender, EventArgs e)
{
Button b = new Button();
b.Name = "btnSubmit";// creating here for intellisense - you would create on your front-end
bool recordExists = true;
Button b1 = Controls.Find("btnSubmit", true)[0] as Button;
//the above is for winforms - you'd have to change for web form
b1.Text = recordExists ? "Update" : "Save";
b1.Click += doUpdateOrSave;
}
protected void doUpdateOrSave(object sender, EventArgs e)
{
Button b = sender as Button;
if (b.Text == "Save")
{
//save
}else
{
//update
}
}
I'm trying to disable the two list boxes on load of my web form, but the list boxes are not disabling. I tried the code below but it's still not working on my case. Please let me know where I'm going wrong.
DESIGNER CODE
<telerik:RadListBox ID="lbSelectedDepartmentContacts" runat="server" Width="220px" AutoPostBackOnTransfer="true" AutoPostBackOnReorder="true" AutoPostBackOnDelete="true" CheckBoxes="false" AllowTransfer="true" AllowTransferOnDoubleClick="true" TransferToID="lbDepartmentContacts"
Height="276px" SelectionMode="Single" AllowReorder="True">
<ButtonSettings ShowTransfer="false" ShowTransferAll="false" ReorderButtons="Common" ShowReorder="true" />
</telerik:RadListBox>
</td>
</tr>
<tr>
<td align="right">
<telerik:RadListBox ID="lbDepartmentContacts" runat="server" Width="200px" CheckBoxes="false" AutoPostBackOnTransfer="true" AllowTransfer="true" AllowTransferOnDoubleClick="true" TransferToID="lbSelectedDepartmentContacts"
Height="250px" SelectionMode="Single">
<ButtonSettings TransferButtons="Common" ShowTransfer="false" ShowTransferAll="false" />
</telerik:RadListBox>
BACKCODE
public void DisableControls()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(#"<script language='javascript'>function DisableControls(){");
sb.Append(#"var lbl = document.getElementById('lbSelectedDepartmentContacts').disabled = true;");
sb.Append(#" var Txt = document.getElementById('txtDepartmentCategoryContactsFilter').disabled = true;");
sb.Append(#" var btn = document.getElementById('RadButton1').disabled = true;");
sb.Append("}</script>");
if (!ClientScript.IsClientScriptBlockRegistered("JSScriptBlock"))
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "JSScriptBlock",
sb.ToString());
}
string funcCall = "<script language='javascript'>DisableControls();</script>";
if (!ClientScript.IsStartupScriptRegistered("JSScript"))
{
ClientScript.RegisterStartupScript(this.GetType(), "JSScript", funcCall);
}
}
Tried Also:
Page.ClientScript.RegisterStartupScript(this.GetType(), "text", "DepartmentLoad();", true);
JAVASCRIPT CODE
function DepartmentLoad(){
document.getElementById("lbSelectedDepartmentContacts").disabled = true;
document.getElementById("lbDepartmentContacts").disabled = true;
document.getElementById("txtDepartmentCategoryContactsFilter").disabled = true;
ducument.getElementById("RadButton1").disabled = true;}
C# only approach to disable your 2 listboxes...
Delete or comment out your existing DisableControls() method then add the following...
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack) return;
DisableControls();
}
private void DisableControls()
{
lbSelectedDepartmentContacts.Enabled = lbDepartmentContacts.Enabled = false;
}
You should generally:
Use Sys.Application.Load to register your script. Calling the function earlier will cause problems with using the client-side API of the IScriptControls: http://msdn.microsoft.com/en-us/library/bb383829.aspx and http://docs.telerik.com/devtools/aspnet-ajax/controls/window/troubleshooting/executing-javascript-code-from-server.
use the API the Telerik control provides: http://docs.telerik.com/devtools/aspnet-ajax/controls/listbox/client-side-programming/objects/radlistbox-object.
There seems to be no set_enabled() or set_disabled() method on the client (at least at the time of writing), so this seems to be impossible with JS, so you should go with the other answer that tells you to use server code.
Currently, I have a working code that selects and transfers gridview row data in a textbox. Here's the code
protected void grdRP_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = grdLocation.SelectedRow;
hdnSearchedLoc.Value = grdLocation.Rows[grdLocation.SelectedIndex].Cells[1].Text;
txtSearchedLoc.Text = HttpUtility.HtmlDecode(row.Cells[2].Text);
}
It works well functionality and performance (speed) wise when it is local. I have seen the difference in speed when I upload it to the web server. it takes 5 seconds and more before it transfer the row data to textbox.
Now, I am thinking of alternative way to make it faster by using javascript since it is on client-side. I have seen a sample code but it is only on selection method but the transfer of row data is still the same speed. Here's the code
javascript
function setMouseOverColor(element)
{
oldgridSelectedColor = element.style.backgroundColor;
element.style.backgroundColor='#C0C0C0';
element.style.cursor='hand';
//element.style.textDecoration='underline';
}
function setMouseOutColor(element)
{
element.style.backgroundColor=oldgridSelectedColor;
element.style.textDecoration='none';
}
aspx.cs
protected void grdRP_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Style["display"] = "none";
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] =
"javascript:setMouseOverColor(this);";
e.Row.Attributes["onmouseout"] =
"javascript:setMouseOutColor(this);";
e.Row.Attributes["onclick"] =
Page.ClientScript.GetPostBackClientHyperlink
(this.grdRP, "Select$" + e.Row.RowIndex);
}
}
is there other javascript way of doing that?
I have a tabpanel with a dropdownlist control on the 4th tab but when I select a item, the postback not occur even autopostback property is true. Is there any way to postback the page when item is selected?
I think this use the javascript code to postback the drop down list please suggest.
Any ideas ?
<asp:DropDownList ID="ddlrole" runat="server" Width="151px" AutoPostBack="True"
onselectedindexchanged="ddlrole_SelectedIndexChanged">
</asp:DropDownList>
code behind is:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//code goes here
}
}
protected void ddlrole_SelectedIndexChanged(object sender, EventArgs e)
{
st = int.Parse(ddlrole.SelectedValue);
}
ddlrole_SelectedIndexChanged is not fire when an item is selected from drop down list?
I use the javascript code to prevent this tab to return to first tab:
<script type="text/javascript">
$(function () {
$("#tabContainer").tabs();
var currTab = $("#<%= HFCurrTabIndex.ClientID %>").val();
$("#tabContainer").tabs({ selected: currTab });
});
</script>