Showing posts with label iam. Show all posts
Showing posts with label iam. Show all posts

Thursday, March 22, 2012

Set Focus using: Clientscript.RegisterStartupscript

Hello,

I am trying to set the focus on an object using the following: However, I
am getting the following error:

The name Clientscript does not exist in the current context.

protected void SetFocusControl(Control FocusControl)
{
StringBuilder script = new StringBuilder();
string ClientID = FocusControl.ClientID;
script.Append("<script language='javascript'>");
script.Append("document.getElementById('");
script.Append(ClientID);
script.Append("').focus();");
script.Append("</script>");
Clientscript.RegisterStartupscript("SetFocusControl", script);
}try it with the correct case

ClientScript.RegisterStartupscript("SetFocusControl", script);

--
Regards

John Timney (MVP)

"sck10" <sck10@.online.nospamwrote in message
news:O23DxRPsGHA.4380@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

Hello,
>
I am trying to set the focus on an object using the following: However, I
am getting the following error:
>
The name Clientscript does not exist in the current context.
>
protected void SetFocusControl(Control FocusControl)
{
StringBuilder script = new StringBuilder();
string ClientID = FocusControl.ClientID;
script.Append("<script language='javascript'>");
script.Append("document.getElementById('");
script.Append(ClientID);
script.Append("').focus();");
script.Append("</script>");
Clientscript.RegisterStartupscript("SetFocusControl", script);
}
>


Thanks John...

"John Timney (MVP)" <x_john@.timney.eclipse.co.ukwrote in message
news:5KednZH2LoThRFrZRVnyiA@.eclipse.net.uk...

Quote:

Originally Posted by

try it with the correct case
>
ClientScript.RegisterStartupscript("SetFocusControl", script);
>
--
Regards
>
John Timney (MVP)
>
>
"sck10" <sck10@.online.nospamwrote in message
news:O23DxRPsGHA.4380@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

>Hello,
>>
>I am trying to set the focus on an object using the following: However,
>I am getting the following error:
>>
>The name Clientscript does not exist in the current context.
>>
>protected void SetFocusControl(Control FocusControl)
>{
> StringBuilder script = new StringBuilder();
> string ClientID = FocusControl.ClientID;
> script.Append("<script language='javascript'>");
> script.Append("document.getElementById('");
> script.Append(ClientID);
> script.Append("').focus();");
> script.Append("</script>");
> Clientscript.RegisterStartupscript("SetFocusControl", script);
>}
>>


>
>


On Wed, 26 Jul 2006 16:39:00 -0500, "sck10" <sck10@.online.nospam>
wrote:

Quote:

Originally Posted by

>Thanks John...
>
>


With 2.0, controls have a Focus method that seems to do the same
thing. Actually a bit better because it takes care of ClientId if
using a master page.

Tuesday, March 13, 2012

Set selected node in Treeview control in ASP:NET 2.0 ? Anyone know this ?

Hello,

Iam using Treeview control in asp.net 2.0. But have a problem.

I use NavigateUrl BUT then viewstate is lost when clicked on a link i
the menu. And the selected node is lost.

Then i have to set the selected node manually, how can i do it ? i have
tried but without luck :(
I have posted my menu code here.

namespace DayDream.Admin.UC
{
public partial class AdminMenu : DayDreamBaseUserControl
{
public string SelectedURL;

protected void Page_Load(object sender, EventArgs e)
{
DataBind();

}

protected void PopulateNode(Object sender, TreeNodeEventArgs e)
{

// Call the appropriate method to populate a node at a
particular level.
switch (e.Node.Depth)
{
case 0:
// Populate the first-level nodes.
PopulateTopLevelNodes(e.Node);
break;
case 1:
// Populate the second-level nodes.
PopulateChildern(e.Node);
break;
default:
// Do nothing.
break;
}

}

private void PopulateTopLevelNodes(TreeNode node)
{
DayDreamBasePage basePage = new DayDreamBasePage();

for (int x = 0; x <
basePage.GetAllPages().Tables[0].Rows.Count; x++)
{
if
(basePage.GetAllPages().Tables[0].Rows[x]["ParentPageID"].ToString().Length
<= 0)
{

TreeNode TopLevel = new TreeNode();

//TopLevel.NavigateUrl =
basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString() +
"?id=" + basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
TopLevel.NavigateUrl =
"../../"+basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString()
+ "?id=" +
basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
TopLevel.Text =
basePage.GetAllPages().Tables[0].Rows[x]["PageName"].ToString();
TopLevel.Value =
basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();

// Add root node to TreeView
TopLevel.PopulateOnDemand = true;
TopLevel.SelectAction =
TreeNodeSelectAction.SelectExpand;
node.ChildNodes.Add(TopLevel);

}

}

}

private void PopulateChildern(TreeNode node)
{

DayDreamBasePage basePage = new DayDreamBasePage();

DataSet Childrens = new DataSet();
Childrens =
basePage.GetChildrenPages(Int32.Parse(node.Value)) ;

for (int y = 0; y < Childrens.Tables[0].Rows.Count; y++)
{

TreeNode newNode = new TreeNode();
newNode.NavigateUrl = "../../" +
Childrens.Tables[0].Rows[y]["Template"].ToString() + "?id=" +
Childrens.Tables[0].Rows[y]["PageID"].ToString();
newNode.Text =
Childrens.Tables[0].Rows[y]["PageName"].ToString();
newNode.Value =
Childrens.Tables[0].Rows[y]["PageID"].ToString();

// Set additional properties for the node.
newNode.SelectAction =
TreeNodeSelectAction.SelectExpand;

// Add the new node to the ChildNodes collection of the
parent node.
node.ChildNodes.Add(newNode);

DataSet ChildrensSub = new DataSet();
int ChildrensSubCount =
basePage.GetChildrenPages(Int32.Parse(newNode.Valu e)).Tables[0].Rows.Count;

if (ChildrensSubCount > 0)
{
PopulateChildern(newNode);
}

}
}

}
}

Thanks
JeppeOn Page_Load event you are not checking if Page isPostBack

If Not (Page.IsPostBack) {
DataBind();
}

Sandeep

"jesper_lofgren@.yahoo.se" wrote:

> Hello,
> Iam using Treeview control in asp.net 2.0. But have a problem.
> I use NavigateUrl BUT then viewstate is lost when clicked on a link i
> the menu. And the selected node is lost.
> Then i have to set the selected node manually, how can i do it ? i have
> tried but without luck :(
> I have posted my menu code here.
>
> namespace DayDream.Admin.UC
> {
> public partial class AdminMenu : DayDreamBaseUserControl
> {
> public string SelectedURL;
> protected void Page_Load(object sender, EventArgs e)
> {
> DataBind();
>
> }
> protected void PopulateNode(Object sender, TreeNodeEventArgs e)
> {
> // Call the appropriate method to populate a node at a
> particular level.
> switch (e.Node.Depth)
> {
> case 0:
> // Populate the first-level nodes.
> PopulateTopLevelNodes(e.Node);
> break;
> case 1:
> // Populate the second-level nodes.
> PopulateChildern(e.Node);
> break;
> default:
> // Do nothing.
> break;
> }
> }
>
> private void PopulateTopLevelNodes(TreeNode node)
> {
> DayDreamBasePage basePage = new DayDreamBasePage();
> for (int x = 0; x <
> basePage.GetAllPages().Tables[0].Rows.Count; x++)
> {
> if
> (basePage.GetAllPages().Tables[0].Rows[x]["ParentPageID"].ToString().Length
> <= 0)
> {
> TreeNode TopLevel = new TreeNode();
> //TopLevel.NavigateUrl =
> basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString() +
> "?id=" + basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
> TopLevel.NavigateUrl =
> "../../"+basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString()
> + "?id=" +
> basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
> TopLevel.Text =
> basePage.GetAllPages().Tables[0].Rows[x]["PageName"].ToString();
> TopLevel.Value =
> basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
> // Add root node to TreeView
> TopLevel.PopulateOnDemand = true;
> TopLevel.SelectAction =
> TreeNodeSelectAction.SelectExpand;
> node.ChildNodes.Add(TopLevel);
>
> }
> }
> }
>
> private void PopulateChildern(TreeNode node)
> {
> DayDreamBasePage basePage = new DayDreamBasePage();
> DataSet Childrens = new DataSet();
> Childrens =
> basePage.GetChildrenPages(Int32.Parse(node.Value)) ;
> for (int y = 0; y < Childrens.Tables[0].Rows.Count; y++)
> {
> TreeNode newNode = new TreeNode();
> newNode.NavigateUrl = "../../" +
> Childrens.Tables[0].Rows[y]["Template"].ToString() + "?id=" +
> Childrens.Tables[0].Rows[y]["PageID"].ToString();
> newNode.Text =
> Childrens.Tables[0].Rows[y]["PageName"].ToString();
> newNode.Value =
> Childrens.Tables[0].Rows[y]["PageID"].ToString();
> // Set additional properties for the node.
> newNode.SelectAction =
> TreeNodeSelectAction.SelectExpand;
> // Add the new node to the ChildNodes collection of the
> parent node.
> node.ChildNodes.Add(newNode);
> DataSet ChildrensSub = new DataSet();
> int ChildrensSubCount =
> basePage.GetChildrenPages(Int32.Parse(newNode.Valu e)).Tables[0].Rows.Count;
> if (ChildrensSubCount > 0)
> {
> PopulateChildern(newNode);
> }
> }
> }
>
> }
> }
>
> Thanks
> Jeppe
>