|
I have a tree view in my page. I want to show the name of of selected node
along with it's parent node. I am using the folleing event. I want my text
of lable like follwing when I click child node aaa
AA--> aaa.
Where AA is parent node's text and aaa is child node's text. I don't want
to use Sitemappath.
|
|
|
|
|
when you clicked the Node Get Parent Nodes of Selected Node
and Show it on label.
Example.
TreeNode ParentNode= new TreeNode();
ParentNode=this.treeviewCtrl.SelectedNode.Parent
string strFullNode=ParentNode.Text + ">>"+ this.treeviewCtrl.SelectedNode.Text
|
|
|
|
|
In my site i have a div to represent a blog post like below
<div class="post">
<div class="header">
<h3>Header</h3>
<div class="date">May 18, 2009</div>
</div>
<div class="content">
Some Content
</div>
</div>
Basically, what i'm wanting to do is select the 10 recent posts from a database and build the page with these posts using the div tags above. I can already do the easy things like setting the header, date, and content.
Thanks,
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
So, what is your question?
|
|
|
|
|
what i can't figure out is how to create dynamically create div's for each post (as opposed to hardcoding them in the aspx file).
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
I think i figured it out. The solution i found is something like this:
(i know this won't generate the markup in the original post, this is in a seperate test project)
ContentPlaceHolder leftContent = (ContentPlaceHolder)Master.FindControl("leftContent");
HtmlGenericControl div = new HtmlGenericControl("div");
div.Attributes.Add("class", "post");
HtmlGenericControl h2 = new HtmlGenericControl("h2");
h2.InnerText = "My Header";
HtmlGenericControl p = new HtmlGenericControl("p");
p.InnerText = "This is some content.";
div.Controls.Add(h2);
div.Controls.Add(p);
leftContent.Controls.Add(div);
which will then generate this:
<div class="post"><h2>My Header</h2><p>This is some content.</p></div>
Is there a better way to achieve what i'm trying to do? I feel like i'm going against the grain here.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Use asp.net repeater control.
<asp:Repeater id="rPOSTS" runat="server">
<ItemTemplate>
</ItemTemplate>
<asp:Repeater> On ItemTemplate you will put the code you want to repeat X times.
So, in code behind you will do something like this:
rPOSTS.DataSouce = YOUR_DB_DATA;
rPOSTS.DataBind();
See more about repeater control in Google[^].
|
|
|
|
|
Sweet! That was easy enough For future readers this is the result that paulo helped me come up with
in the aspx file:
<asp:Repeater runat="server" ID="postRepeater">
<HeaderTemplate>
<div class="post">
</HeaderTemplate>
<ItemTemplate>
<h2>
<%#DataBinder.Eval(Container.DataItem, "Header")%></h2>
<p>
<%#DataBinder.Eval(Container.DataItem, "Content")%></p>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
and in the code behind:
System.Data.DataTable dt = new System.Data.DataTable("Posts");
dt.Columns.Add(new System.Data.DataColumn("Header"));
dt.Columns.Add(new System.Data.DataColumn("Content"));
System.Data.DataRow row = dt.NewRow();
row[0] = "Header 1";
row[1] = "Content 1";
dt.Rows.Add(row);
postRepeater.DataSource = dt;
postRepeater.DataBind();
Thanks again
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
If i have a string that contains a comma how do i write that to a csv file without it thinking they are two different words?
|
|
|
|
|
use a text qualifier. 'joe, blow', 'money, its good', 'do you see a pattern'
I didn't get any requirements for the signature
|
|
|
|
|
It doesn't work. It thinks its two different values and places them in two different cells
|
|
|
|
|
If you want to write something for Excel, do something like this...
System.Data.DataTable DT = TankBookWeb.sqlDataObjects.GetInquiryDetailExcel();
if (DT != null)
{
//clear anything in io buffer
Response.Clear();
//set to excel for to save file.
// Response.AddHeader("Content-Disposition", "attachment;filename=TankBookExport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
//write columns
string tab = "";
foreach (DataColumn dc in DT.Columns)
{
Response.Write(tab + dc.ColumnName);
tab = "\t";
}
Response.Write("\n");
//write rows
int i;
foreach (DataRow dr in DT.Rows)
{
tab = "";
for (i = 0; i < DT.Columns.Count; i++)
{
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
Response.Write("\n");
}
Response.End();
}
As for the csv, you need to tell what program you are using to open the file that their is text qualifier.
I didn't get any requirements for the signature
|
|
|
|
|
I’ve got a simple page that should display the string “OK” when the user clicks the button. It works fine untill I put a RequiredFieldValidator on the page. Now it seems like there is an implicit conditional in the source code that prevents the “OK” from being displayed unless the text box has text in it. I put no such conditional in the code; why is it behaving like this?
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="pageIsValidTest.aspx.vb" Inherits="pageIsValidTest" %>
<!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>
Textbox:
<asp:TextBox ID="TextBox" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox"
ErrorMessage="enter text"></asp:RequiredFieldValidator><br />
<asp:Button ID="Button1" runat="server" Text="Button" /><br />
Label:
<asp:Label ID="Label" runat="server"></asp:Label></div>
</form>
</body>
</html>
Partial Class pageIsValidTest
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label.Text = "OK"
End Sub
End Class
|
|
|
|
|
That is because the RequiredFieldValidator has the ControlToValidate set to the text box. It is working as it should, if no text is in the ControlToValidate the RequiredFieldValidator will prevent your server side code from running.
|
|
|
|
|
Thanks! Didn’t mention that in the book I’m using so I was confused.
But then what is the point of Page.IsValid? If the server side code will only run if all Validators are true then it seems that it would be impossible to get a false Page.IsValid…
What if I want server side code to do something if the form isn't valid, is there a way to override this behavior?
|
|
|
|
|
You can change the "Causesvalidation" of your button to "False" , so it will work without fire the Validators.
i hope it help you.
|
|
|
|
|
Thanks you for the response but not quite what I am looking for. I’m looking for a way to run the source code and within that source code programmatically determine if the page is valid (meaning a validaters = true) and do something it is and something else if its not.
|
|
|
|
|
ok. But you must be more explicit,ex: what are you doing in the page before you do that request?
|
|
|
|
|
Page.IsValid is used to check the validation status at server side. Validation control uses JS by default to do the validation. Since JS is not reliable, ASP.NET does server side validations also to make sure validation logic is not bypassed and set the IsValid flag. So before you continue with your action, check the page is valid. Something like
If(this.IsValid)
bigmish2 wrote: I’m looking for a way to run the source code and within that source code programmatically determine if the page is valid (meaning a validaters = true) and do something it is and something else if its not.
When validator controls are added, by default the validation will happen at the client side. So validating programatically at server side is pointless as form will not postback if there are validation errors. To do the validations on server, you have to disable client side validations first. Set the EnableClientScript property of the validation control to false .
Page class exposes a Validators[^] collection where you can iterate and call Validate() method on each validator to perform the validation. Check the IsValid property to get the status of validation.
|
|
|
|
|
I think I got it now. So if I leave EnableClientScript as true for all validators the code in the source code will only run if all validators are true; the only reason to put Page.IsValid conditional in the source code in this case would be to make sure that the form elements are actually valid and some how the client side validation wasn’t erroneous or by-passed by a user.
If I wanted to do a source code conditional based on form element validity I should set EnableClientScript to false so that the source code will still run even if the user enters in invalid entries.
Thanks all, M
|
|
|
|
|
Hi,
I need to get total size of sessions in my application, I enabled the trace for a page, but it didn't show anything about size of sessions.
How can I get it?
Best wishes
|
|
|
|
|
mehrdadc48 wrote: I need to get total size of sessions in my application
That'd odd. Why do you want to do that? You can't calculate the actual size of objects.
|
|
|
|
|
The classic question is, Does size matters?
|
|
|
|
|
By any chance, do you mean to say number of sessions?
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
hi to all,
I have
button1
and
updatepanel->
Modalpopup Extender->
panel->asp.net controls(UserControls+WebControls)
now when i click on button1 it opens modalpopup but i want to set the tabindex for the controls which are present inside the modalpopup extender
and
the first control i have is usercontrol now
how to set tabindex for this one..
i tried the following one but it is not working
i.e,
Button1_Click(Object Sender,EventArgs e)
{
modalpopupextender1.show();
txtstudent.mandatorytabindex=1 //mandatorytabindex is property of usercontrol and txtstudent in usercontrolname
txtstudent.Focus();
//the above two are not working
}
try to solve this issue.
Regards,
Koti.K
|
|
|
|