In my WebPage, I've an UserControl, When 1st DropDownList's Selected Index is changed, page PostBack event is fired and fills another DropDownList on that UserControl... but my UserControl focus is Lost.... wot i need is, the focus should be transferred
from 1st DropDownList to 2nd... I've used Control.Focus() and Page.SetFocus(Control)... but nothing happens
Can any one plzzzzzzzzzzzzz help me in this scenario...
and one more thing when i try to register my client script from UserControl using
ClientScript.RegisterClientScriptBlock...and try to call a function written in JavaScript... no function is called... is there any other method to register ClientScript.... (without using
Control.Attributes.Add();)
if you are using script tag in you scripts element no need to use true..... true or false is used to set whether the system need to add <script> tag with your code dynamically.....
Thank you so much Mr Vasanthakumar, for taking interest to help me...
Now I've used the code u sent... and I've put this code in my page load event and by doing this at least i got Control over my UserControl... but again the problem is not solved.... let me elaborate it more....
In my website i've a master page which contains some link buttons... when my DropDownList selected index is changed, the control goes over these linkButtons instead of my another DropDownList....
Partial
Class test
Inherits System.Web.UI.UserControl
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender
As Object,
ByVal e As System.EventArgs)
Handles DropDownList1.SelectedIndexChanged
Page.ClientScript.RegisterStartupScript(
Me.GetType(),
"foc", "document.getElementById('" + DropDownList2.ClientID +
"').focus();",
True)
End Sub
Protected
Sub Page_Load(ByVal sender
As Object,
ByVal e As System.EventArgs)
Handles Me.Load
End Sub
One more thing when i use Mouse to select my DropDownList the control is lost and when i use arrow keys to select then control is transferred... y this happens plz guide me[:D]
itsnasir
Member
46 Points
49 Posts
DropDownList Focus is Lost!!!
Feb 29, 2008 10:43 AM|LINK
Hii
In my WebPage, I've an UserControl, When 1st DropDownList's Selected Index is changed, page PostBack event is fired and fills another DropDownList on that UserControl... but my UserControl focus is Lost.... wot i need is, the focus should be transferred from 1st DropDownList to 2nd... I've used Control.Focus() and Page.SetFocus(Control)... but nothing happens
Can any one plzzzzzzzzzzzzz help me in this scenario...
and one more thing when i try to register my client script from UserControl using ClientScript.RegisterClientScriptBlock...and try to call a function written in JavaScript... no function is called... is there any other method to register ClientScript.... (without using Control.Attributes.Add();)
Thanks
Nasir Ibrahim
javascript ASP.NET 2.0 usercontrols
vasanth.kuma...
Contributor
5324 Points
1041 Posts
Re: DropDownList Focus is Lost!!!
Feb 29, 2008 10:56 AM|LINK
Hi,
you can achieve this usign Javascript...
Page.ClientScript.RegisterStartupScript(this.GetType(),"foc","document.getElementById('dropdownId').focus();",true);
write the above code in your first dropdown index changed event....
Software Engineer.
itsnasir
Member
46 Points
49 Posts
Re: DropDownList Focus is Lost!!!
Feb 29, 2008 11:21 AM|LINK
Thanks for ur Reply...
i've already used it [:(] ... But its not working...
Here is My Code;
protected void cmbTradeType_SelectedIndexChanged(object sender, EventArgs e)
{
if(cmbTradeType.SelectedValue != "-1")
{
FillSettlementDate(cmbTradeType.SelectedValue, ""); //Function Called To Fill cmbSettlementDate
cmbSettlementDate.Enabled = true;//Enable cmbSettlementDate
}
if (cmbTradeType.SelectedValue == "-1")
{
cmbSettlementDate.Enabled = false;
}
Page.ClientScript.RegisterStartupScript(this.GetType(), "focus", "<SCRIPT language='javascript'> document.getElementById('ctl00_ContentPlaceHolder1_cfsTrade1_cmbSettlementDate').focus();</SCRIPT>", true); //Set Focus on cmbSettlementDate
}
Now Control should be transferred to cmbSettlementDate, but its really not working [:'(]
vasanth.kuma...
Contributor
5324 Points
1041 Posts
Re: DropDownList Focus is Lost!!!
Mar 01, 2008 03:07 AM|LINK
Hi,
try this...
Page.ClientScript.RegisterStartupScript(
this.GetType(), "foc", "document.getElementById('" + DropwdownName.ClientID + "').focus();", true);if you are using script tag in you scripts element no need to use true..... true or false is used to set whether the system need to add <script> tag with your code dynamically.....
Software Engineer.
itsnasir
Member
46 Points
49 Posts
Re: DropDownList Focus is Lost!!!
Mar 01, 2008 05:29 AM|LINK
Hi
Thank you so much Mr Vasanthakumar, for taking interest to help me...
Now I've used the code u sent... and I've put this code in my page load event and by doing this at least i got Control over my UserControl... but again the problem is not solved.... let me elaborate it more....
In my website i've a master page which contains some link buttons... when my DropDownList selected index is changed, the control goes over these linkButtons instead of my another DropDownList....
Now plz help me[:)]
Thanks
Nasir Ibrahim
vasanth.kuma...
Contributor
5324 Points
1041 Posts
Re: DropDownList Focus is Lost!!!
Mar 01, 2008 05:58 AM|LINK
Hi,
its working nicely for me.... please find the full test code here....
test.master.vb
<%
@ Master Language="VB" CodeFile="test.master.vb" Inherits="test" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><
html xmlns="http://www.w3.org/1999/xhtml" ><
head runat="server"> <title>Untitled Page</title></
head><
body> <form id="form1" runat="server"> <div> <asp:contentplaceholder id="ContentPlaceHolder1" runat="server"> </asp:contentplaceholder> </div> </form></
body></
html>Test.ascx
<%
@ Control Language="VB" AutoEventWireup="false" CodeFile="test.ascx.vb" Inherits="test" %><
asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"> <asp:ListItem>one</asp:ListItem> <asp:ListItem>two</asp:ListItem> <asp:ListItem>thre</asp:ListItem> <asp:ListItem>four</asp:ListItem></
asp:DropDownList><br /> <br /><
asp:DropDownList ID="DropDownList2" runat="server"> <asp:ListItem>one</asp:ListItem> <asp:ListItem>tow</asp:ListItem> <asp:ListItem>three</asp:ListItem></
asp:DropDownList>test.ascx.vb
Partial Class test Inherits System.Web.UI.UserControl Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChangedPage.ClientScript.RegisterStartupScript(
Me.GetType(), "foc", "document.getElementById('" + DropDownList2.ClientID + "').focus();", True) End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End SubEnd
ClassDefault2.aspx
<%@ Page Language="VB" MasterPageFile="~/test.master" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" title="Untitled Page" %><%
@ Register Src="test.ascx" TagName="test" TagPrefix="uc1" %><
asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <uc1:test ID="Test1" runat="server" /></
asp:Content>please check this.... can you post your code....
Software Engineer.
itsnasir
Member
46 Points
49 Posts
Re: DropDownList Focus is Lost!!!
Mar 01, 2008 07:04 AM|LINK
Here is My Code
Master Page
<%@ Master Language="C#" AutoEventWireup="true" Inherits="Main" Codebehind="Main.master.cs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>InvestConnect - FrontEnd</title>
<link href="App_Themes/MSN_Blue/default.css" rel="Stylesheet" type = "text/css" />
<link href="CssFiles/LeftMenuCSS.css" rel="stylesheet" type="text/css" />
<link href="CssFiles/style.css" rel="stylesheet" type="text/css" />
<link href="CssFiles/TopMenu.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<div class="wrapper" style="width:1100px;" >
<table border="0" cellpadding="0" cellspacing="0" style="width:1100px;; height: 100%">
<tr>
<td colspan="2" style="height: 1px;background-image:url('images/topBanner.gif');width:400px">
<div class ="mymenu" style="float:Left; width: 400px; height:25px" >
<asp:LinkButton ID="LinkButton1" runat="server" TabIndex="30" >Report1</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" TabIndex="31">Report2</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" TabIndex="32">Report3</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" TabIndex="33">Report4</asp:LinkButton>
</div>
</td>
</tr>
<tr>
<td colspan="2" style="height: 1px;width:400px">
</td>
</tr>
<tr>
<td colspan="2" style="width:1100px; height: 12px;background-image:url('images/topBanner.gif');width:400px" align="left" >
<div class ="mymenu" style="float:Left; width: 400px; height:25px" >
<asp:LinkButton ID="linkEquity" runat="server" Text = "Equity" Enabled="False" OnClick="linkEquity_Click" TabIndex="34" ></asp:LinkButton>
<asp:LinkButton ID="linkCFS" runat="server" Text ="CFS" Enabled="False" OnClick="linkCFS_Click" TabIndex="35" ></asp:LinkButton>
  <asp:LinkButton ID="linkFIS" runat="server" Text ="FIS" Enabled="False" OnClick="linkFIS_Click" TabIndex="36" ></asp:LinkButton>
  <asp:LinkButton ID="linkMM" runat="server" Text ="MM" Enabled="False" TabIndex="37"></asp:LinkButton>
</div>
</td>
</tr>
<tr>
<td colspan="2" style="width:1100px; height: 14px;" align="left" >
<div id="divWelcome" class="banner" style="width: 100%; height: 25px;text-align:left" >
<h3>Welcome - <asp:Label ID="lblUserName" runat="server"></asp:Label>
<asp:LinkButton ID="linkSignOut" runat="server" OnClick="linkSignOut_Click">Sign Out</asp:LinkButton></h3>
</div>
</td>
</tr>
<tr>
<td style="height:100%; width: 1050px;">
<div class="rightcolumn">
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</td>
</tr>
<tr>
<td colspan="2" background="images/topBanner.gif" style="height: 34px;" width="1012px">
<div align="center" style="font-size:x-small">
<a href="" >Contact us</a>
<a href="" >About us</a>
<a href="" >Terms of use</a><br/>
Copyright © 2008<a href="http://www.softech.com.pk"> Softech Systems</a>. All Rights
Reserved
</div>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
UserControl
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CFSTrade.ascx.cs" Inherits="FrontEnd.CFSTrade" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<div style=" background-color:#D3E8FD; padding: 10px; width:650px">
<fieldset id="FIELDSET1" style="height:320px">
<legend style="font-family:Verdana; font-size:small;">
CFS Trade
</legend>
<center>
<asp:UpdatePanel ID = "upCFS" runat = "server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID ="lblSaveMsg" runat ="Server" ForeColor = "Red" Visible = "false"></asp:Label>
<table id="tbCFS" cellpadding="4" cellspacing="0" align="center" styl
<tr>
<td align="right" style="height: 22px; width:152px">
<asp:Label ID = "Label5" runat="server" Text = "*" ForeColor = "red"></asp:Label>
 <asp:Label ID = "lblTradeType" Text = "Trade Type" runat = "server"></asp:Label>
</td>
<td style="width: 167px; height: 22px;">
<asp:DropDownList ID ="cmbTradeType" runat="server" Width = "156px" OnSelectedIndexChanged="cmbTradeType_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="-1">--</asp:ListItem>
<asp:ListItem Value="002">NCSS COT</asp:ListItem>
<asp:ListItem Value="007">R NCSS COT</asp:ListItem>
</asp:DropDownList>
</td>
<td align="right" style="height: 22px; width: 9px;">
</td>
<td align="right" style="height: 22px">
</td>
<td align="right" style="height: 22px; width:140px" >
<asp:Label ID = "Label7" runat="server" Text = "*" ForeColor = "red"></asp:Label>
 <asp:Label ID = "lblSettlementDate" Text = "Settlement Date" runat = "server"></asp:Label>
</td>
<td style="width: 167px; height: 22px;">
<asp:DropDownList ID ="cmbSettlementDate" runat="server" Width="156px"></asp:DropDownList>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</center>
</fieldset>
</div>
UserControl CodeBehind
protected void cmbTradeType_SelectedIndexChanged(object sender, EventArgs e)
{
if(cmbTradeType.SelectedValue != "-1")
{
cmbSettlementDate.Enabled = true;
FillSettlementDate(cmbTradeType.SelectedValue, "");
if (cmbTradeType.SelectedValue == "002")
{
EnableControls(true);
}
else
{
EnableControls(false);
}
}
if (cmbTradeType.SelectedValue == "-1")
{
cmbSettlementDate.Enabled = false;
}
Page.ClientScript.RegisterStartupScript(this.GetType(), "foc", "document.getElementById('" +cmbSettlementDate.ClientID+"').focus();", true);
}
private void FillSettlementDate(string tradeType, string fPeriod)
{
FrontEnd.BLL.EquityTrade ObjEquiTrade = new FrontEnd.BLL.EquityTrade();
ListItem LI = new ListItem();
LI.Text = "--";
LI.Value = "-1";
DataTable dt = ObjEquiTrade.GetSettlementDate(tradeType, fPeriod);
this.cmbSettlementDate.DataSource = dt;
this.cmbSettlementDate.DataTextField = "CLEARING_DESC";
this.cmbSettlementDate.DataValueField = "CLEARING_NO";
this.cmbSettlementDate.DataBind();
this.cmbSettlementDate.Items.Insert(0, LI);
}
vasanth.kuma...
Contributor
5324 Points
1041 Posts
Re: DropDownList Focus is Lost!!!
Mar 01, 2008 07:44 AM|LINK
Hi,
Page.RegisterStartupScript wont work in update panel..
you need to use
ScriptManager.RegisterStartupScript(this
, this.GetType(), "foc", "document.getElementById('" + cmbSettlementDate.ClientID + "').focus();", true);Software Engineer.
itsnasir
Member
46 Points
49 Posts
Re: DropDownList Focus is Lost!!!
Mar 01, 2008 08:23 AM|LINK
Hi
Thank you sooooooooooo much
well there are 3 userControls in my WebPage... that's y um using
ScriptManagerProxy1.Page.ClientScript.RegisterStartupScript(this.GetType(), "foc", "document.getElementById('" + cmbSettlementDate.ClientID + "').focus();", true);One more thing when i use Mouse to select my DropDownList the control is lost and when i use arrow keys to select then control is transferred... y this happens plz guide me[:D]
vasanth.kuma...
Contributor
5324 Points
1041 Posts
Re: DropDownList Focus is Lost!!!
Mar 01, 2008 08:34 AM|LINK
Hi,
sorry I cannot get you...
can you give me some details?...
please mark as answer the if the post help you...
Software Engineer.