Showing posts with label link. Show all posts
Showing posts with label link. Show all posts

Saturday, March 31, 2012

Set a hyperlink to open in window.

how do you set a hyperlink to open the link in a new window/browser, so I dont lose my current place in the site.

you have to do this with client code

<a href="http://links.10026.com/?link=blah" TARGET="_new"...>

the "_new" is a name you assign to a window. Use that with more then one call and they will reuse the window.

You can't specify the window (new or otherwise) with a Response.Redirect() or any other server call, sorry...


If you need to do this in the code behind and not in the HTML you can use this syntax:

Me.ClientScript.RegisterClientScriptBlock(Me.GetType,"open","<script language=javascript>window.open('http://www.yourpage.aspx');</script>")


Simply the below code

<a href="http://links.10026.com/?link=WebForm1.aspx" target="_blank">Open new window</a>

HC


As everybody as already said

<a href="http://links.10026.com/?link=URL" target="_blank>Clicking on this opens a new window</a>

however if you are using hyperlink button in asp.net then

<asp:HyperLinkid="value"Runat="Server"
ImageUrl="url"
NavigateUrl="url"
Target="_blank|_self|_top|_parent|framename"
Text="string"
property="value"
Style="CSS style settings..."
/>

you can choose target=_blank as described.

Hope that helps and good luck

Thursday, March 29, 2012

Set Code Behind Property from Javascript / link?

I got a property in my code behind, nl "Language" with Get and Set accessors.

On my form I want to put a link (html, not asp) who's target is a javascript in my <head> section.
Then I want this Javascript to set the value of my Language property, and in the Set accessor for the property, do some stuff.

Is it possible to set the property in the code behind from your page? Maybe i should just use an asp label running on the server, but I'm trying to see how far i can stay away from anything causing a postback.The Language property exists in the codebehind. You do realize that at some point, you will have to have a postback so that the property can be assigned that value and perform whatever actions it wants to perform. Get it?

You will eventually have to use some sort of a server-side control for this. Here's what I would suggest.

Add a hidden field to your page. When the user clicks on the hyperlink, the javascript function assigns a value to that hidden field. When the page posts back, in the page load event, assign the value of the hidden field to your property. Then let the property do whatever with it.

No, you cannot avoid the postback as far as you've described your setup.
Actually I was stupid anyhow. When hte language change, I got to reload the form with the different language.

I never use hidden fields though. Nevermind

Thanks for reply M.
No prob.
Just been thinking.
What if one do want to set a code behind property from the page?
What if you do want to call a code behind fucntion from a javascript, sitting in hte head section, called by for instance a link clicked?
The answer to your first question is above ^^

The answer to your second question is a little complex. You will need to use javascript to force a postback. You can do this in one of two ways. For example, if you want to call a button's click event, you can call it like

document.getElementById('buttonid').click();

The second way to do this is quite generic. You can use javascript to force a postback.

http://weblogs.asp.net/mnolton/archive/2003/06/04/8260.aspx

Saturday, March 24, 2012

set focus to form after postback

Hi.

I have one datalist and i have done custom paging for it.

I have four link button "First","Previous","Next", "Last" for paging datalist

Now I want to do paging on key press like as Right arrow for Next,Left Arrow for Previous,..........

for that I am calling javascript on onkeypress event of form.

Now Its working fine but problem is that javascript is called only on form key press event.

so that I want to set out focus on form after every post back.

I am calling following line at last but not working.

this.form1.Focus();

plz any one can help me?

best regard

pathan

Try this Just a guess

<formdefaultfocus="form1"id="form1"runat="server">


not helpful

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
>