I want to retrieve the primary and secondary site administrators using javascript and show them in the labels on custom Access Denied page. Using the code below(inline javascript) to do that but SP.SOD.ExcuteFunc() does not get executed. Am I missing something?
<asp:Content ID="Content5" ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script type="text/javascript">
SP.SOD.RegisterSod("sp.js", "\_layouts\sp.js");
</script>
<script type="text/javascript">
debugger;
alert("check");
var clientContext;
var siteCollection;
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getAdmin);
function getAdmin(){
alert("Entering into function");
var currentContext = SP.ClientContext.get_current();
//alert("1");
var siteColl = clientContext.get_site();
var rootWeb = siteColl.get_rootWeb();
this.props = rootWeb.get_allProperties();
clientContext.load(rootWeb);
clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
//alert("end");
}
//alert("After");
function onRequestSucceeded()
{
alert("inside onrequest");
var primarySiteContact = this.props.get_item('GA_PrimarySiteCollectionContact');
var secondarySiteContact = this.props.get_item('GA_SecondarySiteCollectionContact');
elem = document.getElementById('lblPrimary');
elem.innerHTML = primarySiteContact;
alert(primarySiteContact);
}
function onRequestFailed(sender, args)
{
alert('Error: ' + args.get_message());
}
</script>
<table border="0" cellpadding="0">
<asp:Panel id="PanelUserName" runat="server">
<tr>
<td class="ms-sectionheader">
<img src="/_layouts/images/ListSet.gif" alt="" />
<SharePoint:EncodedLiteral ID="EncodedLiteral3" runat="server" text="<%$Resources:wss,accessDenied_currentuser%>" EncodeMethod='HtmlEncode'/>
</td>
</tr>
<tr>
<td valign="top" class="ms-descriptiontext"><SharePoint:EncodedLiteral ID="EncodedLiteral4" runat="server" text="<%$Resources:wss,accessDenied_loggedInAs%>" EncodeMethod='HtmlEncode'/>
<b><asp:Label id="LabelUserName" runat="server"/></b>
</td>
</tr>
</asp:Panel>
<tr>
<td> </td>
</tr>
<tr>
<td>
<asp:HyperLink id="HLinkLoginAsAnother" Text="<%$SPHtmlEncodedResources:wss,accessDenied_logInAsAnotherOne%>"
CssClass="ms-descriptiontext" runat="server"/>
<br/>
<asp:HyperLink id="HLinkRequestAccess" Text="<%$SPHtmlEncodedResources:wss,accessDenied_requestAccess%>"
CssClass="ms-descriptiontext" runat="server" /><br /><br />
<asp:Label id="Label1" runat="server" Text="Please contact the below mentioned site owners" /><br/>
<asp:Label id="lblPrimary" runat="server" /><br/>
<asp:Label id="lblSecondary" runat="server" />
</td>
</tr>
</table>
</asp:Content>
Related
In the below code there is a radiobuttonlist control and Multiline textbox. On button click I would need to check whether textbox query should contain any WHERE clause. If yes then will get executed directly, but if not then should get confirmation box. If clicked on "Ok" then should get proceed but if clicked on "Cancel" then process get terminated there itself.
In my case confirmation box is not popping up and how to get it's value at code behind?
For this I would have followed an article as
https://www.aspsnippets.com/Articles/Server-Side-Code-Behind-Yes-No-Confirmation-Message-Box-in-ASPNet.aspx
below is my code
HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function alertmsg(m) {
alert(m);
}
function alertmsgwithYesNo(m) {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm(m)) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<table width="100%">
<tr>
<td align="center" valign="top">
<table cellspacing="5">
<tr>
<td align="left" valign="top"><strong>Options : </strong>
<asp:RadioButtonList ID="RadioButtonListoptions" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="1">Execute Directly</asp:ListItem>
<asp:ListItem Value="2">Display In Gridview</asp:ListItem>
<asp:ListItem Value="3">Display On Label</asp:ListItem>
</asp:RadioButtonList> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Select option" ControlToValidate="RadioButtonListoptions" Display="Dynamic" SetFocusOnError="true" ForeColor="Red"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="left" valign="top">
<asp:TextBox ID="TextBoxQuery" runat="server" TextMode="MultiLine" Height="400px" Width="800px" placeholder="Enter query..." Font-Size="Large" Text="" Style="padding: 5px;"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Enter your query" ControlToValidate="TextBoxQuery" Display="Dynamic" SetFocusOnError="true" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="ButtonSubmitQuery" runat="server" Text="Submit" Width="200px" Height="30px" OnClick="ButtonSubmitQuery_Click" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" valign="top">
<asp:Label ID="LabelShowData" runat="server" Text="Label Here"></asp:Label>
<asp:GridView ID="GridViewData" runat="server" AutoGenerateColumns="true" EmptyDataText="No record found."></asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceData" runat="server"></asp:SqlDataSource>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
C#:
protected void ButtonSubmitQuery_Click(object sender, EventArgs e)
{
if (RadioButtonListoptions.SelectedIndex != -1)
{
if (Convert.ToInt32(RadioButtonListoptions.SelectedItem.Value.ToString()) == 1)
{
if (!TextBoxQuery.Text.ToString().Contains("Where"))
{
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "message", "alertmsgwithYesNo('Entered query did not have WHERE condition.');", false);
//ClientScript.RegisterClientScriptBlock(this.GetType(), "UpdateTime", "alertmsgwithYesNo('Query did not have WHERE Condition. Do you want to run it without Where Con');", true);
string confirmValue = Request.Form["confirm_value"];
Label1.Text = confirmValue;
return;
}
using (SqlConnection conn = new SqlConnection(vali.constr))
{
try
{
using (SqlCommand cmdsql = new SqlCommand(TextBoxQuery.Text.Trim()))
{
conn.Open();
int count = cmdsql.ExecuteNonQuery();
if (count > 0)
{
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "message", "alertmsg('Select Option');", false);
}
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
}
}
}
else
{
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "message", "alertmsg('Select Option');", false);
return;
}
}
I have a UserControl "Day" that is repeated 5 times in another UserControl for 5 weekdays in a week that means each day 1 UserControl. And in this UserControl has RadioButtonList rdlAmountSlot is repeated 4 times with the below data
rdlAmountSlot_0 - Amount1 --- (1 - 100)
rdlAmountSlot_1 - Amount2 --- (100 - 1000)
rdlAmountSlot_2 - Amount3 --- (1000 - 10000)
rdlAmountSlot_3 - Amount4 --- (10000 - 100000)
I used the below code for confirmation from the user
$(document).ready(function(){
$("[id^='rdlAmountSlot_'][type='radio']").change(function () {
var radioBtnId = this.id;
var $this = $(this);
radconfirm('Are you sure you want to select this slot?', function(arg){
if (arg == true) {
$find('<%= FindControl("txtAmount").ClientID %>').set_value("");
}
else {
$this.siblings('input').prop('checked',true);
var rdlAmountSlot = document.getElementById(radioBtnId);
rdlAmountSlot.checked = false;
$this.prop('checked', false);
}
}, 300, 100,"");
});
});
The above code is throwing confirmation box for 5 times. What could be the reason and how to resolve it?
UPDATE
Below is my markup code for each day
<asp:UpdatePanel runat="server" ID="pnlUpdate" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlDayView" runat="server">
<asp:RadioButtonList ID="rdlAmountSlot" CssClass="radio1" runat="server" ClientIDMode="Static">
</asp:RadioButtonList>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Below is the markup for 5 days
<table>
<tr>
<td>
<asp:Panel ID="pnlMonday" runat="server" >
<uc1:My ID="MyMonday" runat="server" />
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlTuesday" runat="server" >
<uc1:My ID="MyTuesday" runat="server" />
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlWednesday" runat="server" >
<uc1:My ID="MyWednesday" runat="server" />
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlThursday" runat="server" >
<uc1:My ID="MyThursday" runat="server" />
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlFriday" runat="server" >
<uc1:My ID="MyFriday" runat="server" />
</asp:Panel>
</td>
</tr>
<table>
This is the code similar to rdlAmountSlot
<table id="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability" class="radio1" border="0" style="color: #004B59; font-size: 11px; font-family: Arial, Sans-serif; text-align: justify">
<tr>
<td><span disabled="disabled"><input id="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_0" type="radio" name="ctl00$ContentPlaceHolder1$MyAvailability$MyAvailabilityMonday$rdlAvailability" value="AVL01" disabled="disabled" /><label for="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_0">Slot 0</label></span></td>
</tr><tr>
<td><input id="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_1" type="radio" name="ctl00$ContentPlaceHolder1$MyAvailability$MyAvailabilityMonday$rdlAvailability" value="AVL02" /><label for="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_1">Slot 1</label></td>
</tr><tr>
<td><input id="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_2" type="radio" name="ctl00$ContentPlaceHolder1$MyAvailability$MyAvailabilityMonday$rdlAvailability" value="AVL03" /><label for="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_2">Slot 2</label></td>
</tr><tr>
<td><input id="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_3" type="radio" name="ctl00$ContentPlaceHolder1$MyAvailability$MyAvailabilityMonday$rdlAvailability" value="AVL04" checked="checked" /><label for="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_3">Slot 3</label></td>
</tr>
</table>
May be if you try with each it would work.
$(document).ready(function(){
$("[id^='rdlAmountSlot_'][type='radio']").each(function () {
$(this).change(function(){
var radioBtnId = this.id;
var $this = $(this);
radconfirm('Are you sure you want to select this slot?', function(arg){
if (arg == true) {
$find('<%= FindControl("txtAmount").ClientID %>').set_value("");
}
else {
$this.siblings('input').prop('checked',true);
var rdlAmountSlot = document.getElementById(radioBtnId);
rdlAmountSlot.checked = false;
$this.prop('checked', false);
}
}, 300, 100,"");
})
});
});
I need to validate the input so the difference between Date1 and Date2 no more then 30 days.
I'm trying to use custom validation in asp.net, but not sure if in my case it would be the correct choice.
I have the following html:
.
.
.
<tr>
<td>
<asp:Label ID="lblFileDate" runat="server">File Date: from</asp:Label>
</td>
<td>
<asp:TextBox ID="txtDateFrom" runat="server" CssClass="datepicker1"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvDateFrom" runat="server" ControlToValidate="txtDateFrom" ForeColor="Red" ErrorMessage="Date From is Required" ValidationGroup="vgForm" >*</asp:RequiredFieldValidator>
</td>
<td style="padding-left:40px; text-align:right;">
<asp:Label ID="lblDateTo" runat="server" >to:</asp:Label>
</td>
<td width="165">
<asp:TextBox ID="txtDateTo" runat="server" colspan="2" CssClass="datepicker2"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvDateTo" runat="server" ControlToValidate="txtDateTo" ForeColor="Red" ErrorMessage="Date To is Required" ValidationGroup="vgForm" >*</asp:RequiredFieldValidator>
<asp:CustomValidator ID="cstDateValidation" runat="server" ErrorMessage="Date difference should not be more then 30 days" ClientValidationFunction="ValidateDateDiff"></asp:CustomValidator>
</td>
</tr>
<tr>
<td style="text-align: right;" colspan="4">
<asp:Button id="btnSearch" Text="Search" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" runat="server"
CausesValidation="true" CommandName="Search" OnCommand="btnSearch_Click" OnClientClick="return ValidateFields()" />
</td>
</tr>
.
.
.
<div id="errorDisplay">
<asp:ValidationSummary ID="vSum" runat="server" ShowSummary="true" ValidationGroup="vgForm"></asp:ValidationSummary>
</div>
This is my javascript:
function ValidateFields() {
var isValid = false;
isValid = Page_ClientValidate('vgForm');
if (!isValid) {
$('#errorDisplay').dialog({
title: "Validation Error",
modal: true,
resizable: false,
width: 250,
buttons: {
Close: function () {
$(this).dialog('close');
}
}
});
return false;
}
return true;
}
function ValidateDateDiff(sender, args) {
var dateFrom = $('#cphBody_Cnt_txtDateFrom').val();
var dateTo = $('#cphBody_Cnt_txtDateTo').val();
var diff = dateFrom - dateTo;
if (diff > 30) {
args.IsValid = false;
}
}
What is the best way to do something like that?
I have an ASP.Net page with 3 textboxes and 1 radiobuttonlist. Each of the 4 controls has
class="tabbable"
in its definition. Here's the complete markup:
<%# Control Language="c#" AutoEventWireup="false" Codebehind="approvalacctprocess.ascx.cs" Inherits="cmc.workflow.ui.ApprovalAcctProcess" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<%# Register tagprefix="CMC" Tagname="ApprovalComments" src="~/workflow\ui\ApprovalComments.ascx" %>
<script src="../../Scripts/jquery-1.4.1.js"></script>
<asp:Panel ID="pnlApprovalAC" CssClass="STDPANEL" HorizontalAlign="Center" Runat="server" Width="550">
<TABLE cols="2" width="520">
<TR>
<TD class="FLDLABEL" style="VERTICAL-ALIGN: top">Client Number</TD>
<TD>
<asp:TextBox id=txtclnum style="VERTICAL-ALIGN: top" Width="300" Runat="server" CssClass="FLDVALUE" TabIndex="0" onchange="MoveNext(this);" Text='<%# Property["clnum"] %>' MaxLength="14" AutoPostBack="True" class="tabbable"></asp:TextBox>
<asp:RegularExpressionValidator id="rxClNum" ValidationExpression="^[0-9]+[ ]*$|Clt Number TBD" ErrorMessage="Client Number consists of up to 14 numbers"
ControlToValidate="txtclnum" runat="Server"></asp:RegularExpressionValidator></TD>
<TR>
<TD class="FLDLABEL" style="VERTICAL-ALIGN: top">Matter Number (5-6 digit)</TD>
<TD>
<asp:Label id=lbclnum style="TEXT-ALIGN: right" Width="140" Runat="server" Text='<%# Property["clnum"] %>' Font-Name="verdana" Font-Size="x-small">
</asp:Label>-
<asp:TextBox id=txtmmatter Width="150" Runat="server" CssClass="FLDVALUE" TabIndex="1" Text='<%# Property["mmatter"] %>' MaxLength="6" AutoPostBack="True" class="tabbable"></asp:TextBox>
</TD>
<TR>
<TD colSpan="2">
<HR style="COLOR: gray; TEXT-ALIGN: left" SIZE="1">
</TD>
</TR>
<tr>
<td class="FLDLABEL" style="VERTICAL-ALIGN: top" width="500" colspan="2"><asp:Label runat="server" ID="lbExistingClientQuestion" Text="Is there an Engagement Letter on file for this client?" Visible="false" />
<asp:Label runat="server" ID="lbUDFRetainerLetter" Text='<%# Property["RetainerLetter"] %>' Visible="false" /></td>
</tr>
<TR>
<TD class="FLDLABEL" style="VERTICAL-ALIGN: top" width="500" colSpan="2">Has a
retainer/engagement letter been submitted and approved by Charlotte Fischman?</TD>
</TR>
<TR>
<TD colSpan="2">
<asp:RadioButtonList id="rblRetLtrReturned" TabIndex="2" Runat="server" CssClass="RADIOBUTTONLIST" RepeatDirection="Horizontal" class="tabbable"
RepeatLayout="Table" RepeatColumns="1" width="300" AutoPostBack="True">
<asp:ListItem Value="0">No</asp:ListItem>
<asp:ListItem Value="1">Yes</asp:ListItem>
</asp:RadioButtonList>
<asp:Label id="lblnoretainerltrneeded" Runat="server" CssClass="SMALLNOTE" Text="(This is an existing client and the matter is in an existing area of law.
A retainer letter may not be needed.)"
Font-Size="xx-small" Visible="False" ForeColor="red"></asp:Label></TD>
</TR>
<TR>
<TD colSpan="2">
</TD>
</TR>
<TR>
<td class="FLDLABEL" style="VERTICAL-ALIGN: top" colSpan="2" width="500">Reason for Not Submitting an Retainer/Engagement Letter for Approval<SPAN style="FONT-WEIGHT: bold; COLOR: red">
*</SPAN>
<asp:Label runat="server" CssClass="SMALLNOTE" Text="(Required if no retainer letter submitted and not an existing client)" Font-Size="XX-Small" ForeColor="Red" /></td>
</TR>
<TR>
<td colspan="2">
<asp:TextBox Width="500" runat="server" TextMode="MultiLine" TabIndex="3" CssClass="FLDVALUE" ID="txtReason" MaxLength="500" Text='<%# Property["Reason"] %>' AutoPostBack="True" class="tabbable" />
</td>
</TR>
<TR>
<TD colSpan="2">
<HR style="COLOR: gray; TEXT-ALIGN: left" SIZE="1">
</TD>
</TR>
<TR>
<TD class="FLDLABEL" style="VERTICAL-ALIGN: top">Comments</TD>
<TD>
<asp:TextBox id="txtComments" style="VERTICAL-ALIGN: top" Width="300" TabIndex="4" Runat="server" CssClass="FLDVALUE"
MaxLength="450" Rows="5" TextMode="MultiLine" Text='<%# Property["AcctgComment"] %>' AutoPostBack="True" class="tabbable"></asp:TextBox></TD>
</TR>
</TABLE>
<TABLE class="STDPANEL" style="VERTICAL-ALIGN: middle" height="50" width="550">
<TR>
<td align="center">
<input id="btnSaveACProperty" runat="server" name="btnSaveACProperty"
onserverclick="OnSave_Click" type="submit" value="Save Status and Comment">
<input id="btnResetACProperty" runat="server" name="btnResetACProperty"
type="reset" value="Cancel">
</input>
</input>
</td>
<tr>
<td align="left">
<asp:ValidationSummary ID="valsum" runat="server" BorderColor=""
BorderStyle="Solid" BorderWidth="2" CssClass="VALIDATORSUM" DisplayMode="List"
Font-Bold="True" ForeColor="red"
HeaderText=" Some errors occurred in your input. Please correct them:<br> "
ShowMessageBox="True" ShowSummary="True" Width="500" />
</td>
</tr>
</TABLE>
</asp:Panel>
<script type="text/vbscript">
</script>
<script type="text/javascript" lang="javascript">
function MoveNext(ele) {
$(document).ready(function () {
var lastTabIndex = 4;
var currentElementID = ele.id; // ID set by OnFocusIn
var currentElement = document.getElementById(currentElementID);
var curIndex = currentElement.tabIndex; //get current elements tab index
if (curIndex == lastTabIndex) { //if we are on the last tabindex, go back to the beginning
curIndex = 0;
}
var tabbables = document.querySelectorAll("tabbable"); //get all tabbable elements
alert(tabbables.length);
for (var i = 0; i < tabbables.length; i++) { //loop through each element
if (tabbables[i].tabIndex == (curIndex + 1)) { //check the tabindex to see if it's the element we want
tabbables[i].focus(); //if it's the one we want, focus it and exit the loop
break;
}
}
});
}
</script>
The textbox txtclnum calls the javascript function MoveNext at the bottom of the page (just to make sure everything loads in the right order)(this is taken from the first answer to this question). MoveNext has an alert in it to tell me what tabbables.length is. The alert returns 0 because the CssClass in the .Net controls overwrites the class="tabbable" in the HTML. I've tried
var tabbables = document.getElementsByTagName("*");
which gets me to the correct control, but the focus doesn't stay on that control. How can I keep the focus on the control?
That function takes as its argument a CSS selector, so if you're looking for elements with class "tabbable" you would use document.querySelectorAll(".tabbable")
Since tabbable is a class, you need to put a period in front of it in your queryselector, so it should be:
document.querySelectorAll(".tabbable")
Edit: Just further clarification, the queryselector without the "." would be looking for html tags like <tabbable>. Since that does not exist, the length returned is 0.
The way you're using it, document.querySelectorAll("tabbable") is looking for an element of the tag <tabbable>. Since it looks like you're trying to query by a class, add the period to denote it is such.
document.querySelectorAll(".tabbable")
When you use document.getElementsByClassName("tabbable") it could work, so I could see where you could get confused if you've used that method in the past.
OK, I feel like an idiot. Just for others' future reference, the problem was that 1) there's a Cssclass assigned to those controls, which overrides my tabbable class in the HTML markup; and 2) once I took care of that (see below code), it still wasn't working because (duh) each control had an AutoPostBack=true on it (they used to have server-side code attached to them). Now that AutoPostBack is false, my code works fine. Here it is:
<script type="text/javascript" lang="javascript">
function MoveNext(currentElement, btnID) {
$(document).ready(function () {
var saveButton = document.getElementById(btnID);
saveButton.disabled = false;
var lastTabIndex = 4;
var curIndex = currentElement.tabIndex; //get current elements tab index
if (curIndex == lastTabIndex) { //if we are on the last tabindex, go back to the beginning
curIndex = 0;
}
var tabbables = document.getElementsByTagName("*"); //get all tabbable elements
for (var i = 0; i < tabbables.length; i++) { //loop through each element
if (tabbables[i].tabIndex != null & tabbables[i].tabIndex == (curIndex + 1)) { //check the tabindex to see if it's the element we want
tabbables[i].focus(); //if it's the one we want, focus it and exit the loop
break;
}
}
});
}
Thanks to everyone for their help.
I'm having a Drop-down-list and a Text-box with auto-completed extender on my web form.
Now i need to set ContextKey property of auto-completed extender from java-script.
I'm trying to set ContextKey property using java-script on onkeyup event of text-box. But it's not working
.aspx code
<table>
<tr>
<td style="width:100px;">
<asp:Label ID="Label1" CssClass="lbl" runat="server" Text="Server:"></asp:Label>
</td>
<td colspan="4">
<asp:DropDownList ID="DropDownList1" CssClass="Comb" runat="server"
OnSelectedIndexChanged="ddlServer_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" CssClass="lbl" runat="server" Text="Originating:"></asp:Label>
</td>
<td colspan="4">
<asp:TextBox runat="server" ID="TextBox1" CssClass="tb10" autocomplete="off" onkeyup="SetContextKey()"/>
<ajaxToolkit:AutoCompleteExtender TargetControlID="TextBox1" UseContextKey="true"
runat="server" BehaviorID="AutoCompleteEx" ID="AutoCompleteExtender1"
ServicePath="AutoComplete.asmx" ServiceMethod="GetResellerList"
MinimumPrefixLength="1" CompletionInterval="1000" EnableCaching="true" FirstRowSelected="true"
CompletionSetCount="20" CompletionListCssClass="cssList" DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true" OnClientHiding="OnClientCompleted"
OnClientPopulated="OnClientCompleted" OnClientPopulating="OnClientPopulating">
</ajaxToolkit:AutoCompleteExtender>
</td>
</tr>
</table>
.cs code (Service Code)
[WebMethod]
public string[] GetResellerList(string prefixText, int count, string contextKey)
{
DataSet ds = new DataSet();
ds = clsTransaction.Select("SELECT nm AS Name FROM tblReseller WHERE nm LIKE '" + prefixText + "%' AND wsid = '" + contextKey + "'",
DataSendBSSWEB.ServerDbEnum.MainSqlServer,
false);
//Then return List of string(txtItems) as result
List<string> txtItems = new List<string>();
String dbValues;
foreach (DataRow row in ds.Tables[0].Rows)
{
dbValues = row["Name"].ToString();
txtItems.Add(dbValues);
}
return txtItems.ToArray();
}
javascript Code
<script type="text/javascript">
function SetContextKey() {
$find('<%=autoComplete2.ClientID%>').set_contextKey($get("<%=ddlServer.ClientID %>").value);
}
</script>
Can any one tell me how can i do this using java-script.
Target control id of the extender should be the TextBox's Id, Not the drop down's.