|
Go to the properties of the text box and make view state as true.
View state will be automatically saved.
Make sure That textbox is server control.
Go to html, make sure that is within tag and include runat = server
hope that helps
|
|
|
|
|
hi,
i have given this piece of code in page Load()
{ DDLSortBy=new DropDownList ();
DataSet ds=new DataSet ();
da.Fill(ds);
DDLSortBy.DataSource = ds.tables[0]
DDLSortBy.DataTextField = "EmpId";
DDLSortBy.DataValueField = "EmpId";
DDLSortBy.DataBind();
DDLSortBy.SelectedIndex = 0;
DDLSortBy .AutoPostBack = true;
DDLSortBy.SelectedIndexChanged += new System.EventHandler(DDLSortBy_SelectedIndexChanged);
plFrm.Controls.Add(DDLSortBy);
}
i am able to retain the value(view state) of the text box inspite of the DDL getting initialized each time on postback.I see no difference if initialize the controls on OnInit() function.
Then why many articles in net suggest us to dynamically add controls in init ftion() .
-- modified at 1:11 Wednesday 28th June, 2006
|
|
|
|
|
I think that it is because you add controls using Controls.add() on its own.
It may place the controls somewhere in the page that is not between form. Check that in the html generated through your browser.
Try using a placeholder where to add your controls and you will have no problems at all cycling through it getting controls infos.
|
|
|
|
|
hi all,
i have 4 radiobuttons on my page. i have set groupname properties of this buttons. now i want to get which radio button was selected. how can i do this?
openup your heart and let the sun shine in
-- modified at 21:26 Tuesday 27th June, 2006
|
|
|
|
|
|
+ Option 1: simply walk through the 4 radiobutton and do checking on the Checked property of each radiobutton.
+ Option 2: use the RadioButtonList control instead of seperate 4 controls, and the control supports a couple of properties SelectedXXX which can help you.
|
|
|
|
|
If it's a RadioButtonList you can use the SelectedItem property to find out which RadioButton is selected.
If you have 4 separate radio buttons you have to check them one by one to find out which one has radioButton.Checked = true;
"Democracy is two wolves and a sheep voting on what to have for dinner" - Ross
Edbert
Sydney, Australia
|
|
|
|
|
thanks for your replies,
i have location problem so i cant use radio button list, i cant check checked properties of them because there are 8 groups = 32 radiobuttons so it could be very nice there is a way like radiobuttonlist selected item property
openup your heart and let the sun shine in
-- modified at 22:52 Tuesday 27th June, 2006
|
|
|
|
|
Hi,
I am plotting a dynamic/multiple web chart objects based on the data that i query from database.
below are my aspx code,
-----------------------
<asp:datalist id="dlScHead" runat="server" ShowFooter="False" ShowHeader="False" CellSpacing="0"
CellPadding="0" Width="100%">
<ItemTemplate>
<table style="FONT-SIZE: 0.8em; font-face: Arial" cellPadding="5" width="100%" align="center"
border="0">
<tr>
<td style="BORDER-RIGHT: #000000 2px solid; BORDER-TOP: #000000 2px solid; BORDER-LEFT: #000000 2px solid; BORDER-BOTTOM: #000000 2px solid"
colSpan="3"><b>
<%# ctype(DataBinder.Eval(Container.DataItem,"ScoreCardID"),string) %>
<%# ctype(DataBinder.Eval(Container.DataItem,"scorecarddesc"),string) %>
</b>
<br>
<%# ctype(DataBinder.Eval(Container.DataItem,"BusinessGoal"),string) %>
</td>
</tr>
</table>
<asp:datalist ID="dlScChart" Width="100%" DataSource='<%# (GetRecords(Cstr(DataBinder.Eval(Container.DataItem, "scoreCardId"))))%>' runat="server">
<ItemStyle VerticalAlign="Top" BackColor="#EEEEEE"></ItemStyle>
<ItemTemplate>
<table>
<tr valign="top">
<td>
<asp:PlaceHolder id="Placeholder1" runat="server"></asp:PlaceHolder>
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
<table style="FONT-SIZE: 0.8em; font-face: Arial" cellPadding="5" width="100%" align="center"
border="0">
<tr>
<td colSpan="3">
<%# Server.htmlDecode(DataBinder.Eval(Container.DataItem,"Quarter1").tostring()) %>
<br>
<br>
<%# Server.htmlDecode(DataBinder.Eval(Container.DataItem,"Quarter2").tostring()) %>
<br>
<br>
<%# Server.htmlDecode(DataBinder.Eval(Container.DataItem,"Quarter3").tostring()) %>
<br>
<br>
<%# Server.htmlDecode(DataBinder.Eval(Container.DataItem,"Quarter4").tostring()) %>
<br>
<br>
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
-----------------------
vb code.
-----------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
objConn = New SqlConnection(dbPath)
Try
objConn.Open()
cmd = New SqlCommand("select * from bizProgram where bizProgId='" & Request.QueryString("bizProgId") & "'", objConn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.Read Then
lblImg.Text = "<img src='/shireplan/images/" & dr("bizProgImg") & "' ALIGN=CENTER BORDER=0 HSPACE=10 ALT='" & dr("bizProgImg") & "'>"
lblProgOutcome.Text = "<b>OUTCOME</b><br>" & dr("bizProgOutcome")
lblProgOper.Text = "<b>OPERATIONAL PROGRAM</b><br>" & dr("bizProgOperational")
lblProgId.Text = dr("bizProgId")
End If
Catch ex As Exception
Response.Write("OOPS.what went wrong:" + ex.ToString)
Finally
objConn.Close()
End Try
dlScHead.DataSource = GetRecords(Nothing)
dlScHead.DataBind()
End Sub
Function GetRecords(ByVal scID As String) As SqlDataReader
Dim bizProgName As String = Request.QueryString("bizProgId")
Dim CommandText As String
Try
objConn = New SqlConnection(dbPath)
objConn.Open()
If scID = Nothing Then
Dim da As New SqlDataAdapter
da.SelectCommand = New SqlCommand
da.SelectCommand.Connection = objConn
da.SelectCommand.CommandText = "select scorecardId,bizProgId,scorecarddesc,businessgoal,strategy,quarter1,quarter2,quarter3,quarter4 from textData where bizProgID='" & Request.QueryString("bizProgId") & "'"
dr = da.SelectCommand.ExecuteReader(CommandBehavior.CloseConnection)
If dr.HasRows Then
'lblError.Text = ""
Else
'lblError.Text = "No records returned"
End If
GetRecords = dr
Else
cmd = New SqlCommand("select distinct measure_id from measuredata where scoreCardId = '" & scID & "'", objConn)
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dtId As New DataTable("MeasureId")
da.Fill(dtId)
'select all columns with ID
Dim cmd1 As SqlCommand = New SqlCommand("select period,actual, target, scorecardid, scorecard,measure_id, measure_desc from measureData where scoreCardId = '" & scID & "'", objConn)
Dim da1 As SqlDataAdapter = New SqlDataAdapter(cmd1)
Dim dt As New DataTable("MeasureSource")
da1.Fill(dt)
Dim datarow As DataRow
For Each datarow In dtId.Rows
Dim chart As New dotnetCHARTING.Chart
chart.Type = dotnetCHARTING.ChartType.Combo
chart.DefaultSeries.DefaultElement.Transparency = 35
chart.TempDirectory = "temp"
chart.ChartArea.XAxis.Label.Text = "Customers"
chart.Debug = True
chart.TempDirectory = "temp"
chart.Width = Unit.Parse(420)
chart.Height = Unit.Parse(300)
Dim myView As New DataView(dt)
myView.RowFilter = String.Format("Measure_Id='{0}'", datarow.Item("measure_Id"))
chart.Series.Name = "Item sales"
chart.Series.Data = myView
chart.SeriesCollection.Add()
Dim i As Integer
For i = 0 To dlScChart.Items.Count - 1
dlScChart.Items(i).FindControl("Placeholder1").Controls.Add(chart)
Next
Next datarow
End If
Catch ex As Exception
Response.Write("error on child" + ex.ToString)
Finally
End Try
End Function
-----------------------
In the above case, the web chart is drawn successfully for different measure ID if i put the placeholder object outside the dlScChart and do followings in vb code
-----------------------
For i = 0 To dlScHead.Items.Count - 1
dlScHead.Items(i).FindControl("Placeholder1").Controls.Add(chart)
Next
-----------------------
but the problem is the scoreCardID 1 is getting measure data for scoreCardId 2 so I am not getting correct webchart for scorecardIds.
can someone help me how it could be fixed so that i can get correct web charts for my scorecard ID.
thanks
|
|
|
|
|
Hi there,
There are a couple of things come to mind:
+ The GetRecords seems not to return the result in the else part.
+ The GetRecords is used to populate the data source for the dlScChart datalist control, so you should not put your code to build its child control (the charting control) in this method. In this case, you might consider using the ItemCreated/ItemDataBound event of the datalist control.
+ The ScoreCardID value contained in the datasource bound to the parent control dlScHead, so if you want to get this value from the child datalist dlScChart, you need to get reference to the DataListItem object of the parent datalist dlScHead. Another option is that you can populate the datasource bound to the child datalist control in a way that it should contain ScoreCardID value. And you can easily access this field when you build the charting control.
|
|
|
|
|
Hi there,
I'd be really grateful if you could please edit my code and show me as i am really having hard time. the next thing that i did was followed your way and now i am just getting able to populate charts with no data but every first measure_id is missing for each scorecard ID.
I did sumthing like this.
aspx
=====
<asp:repeater id="myRepeater" runat="server" OnItemDataBound="myRepeater_ItemDataBound">
<ItemTemplate>
<h3><%#DataBinder.Eval(Container.DataItem, "ScoreCardId")%></h3>
<br />
<asp:repeater id="NestedRepeater" runat="server">
<ItemTemplate>
<h4><%#DataBinder.Eval(Container.DataItem,"Measure_ID")%></h4>
<table><tr><td><asp:PlaceHolder ID="Placeholder1" Runat="server"></asp:PlaceHolder></td></tr></table>
</ItemTemplate>
</asp:repeater>
</ItemTemplate>
</asp:repeater>
===
vb
==
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
objConn = New SqlConnection(dbPath)
cmd = New SqlCommand("select Distinct(ScoreCardId) from measuredata;", objConn)
Dim sdap As New SqlDataAdapter(cmd)
Dim ds As New DataSet
sdap.Fill(ds)
myRepeater.DataSource = ds
myRepeater.DataBind()
End Sub
Public Sub myRepeater_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
Dim dv As DataRowView = e.Item.DataItem '
If Not (dv Is Nothing) Then
Dim nestedRepeater As Repeater = e.Item.FindControl("NestedRepeater") '
If Not (nestedRepeater Is Nothing) Then
objConn = New SqlConnection(dbPath)
Dim scorecardID As String = dv("ScoreCardId").ToString()
cmd = New SqlCommand("select distinct(Measure_ID) from measuredata where ScoreCardID='" & scorecardID & "'; select period,actual, target, scorecardid, scorecard,measure_id, measure_desc from measuredata where ScoreCardID='" & scorecardID & "'", objConn)
Dim subadap As New SqlDataAdapter(cmd)
Dim subDs As New DataSet
subadap.Fill(subDs)
nestedRepeater.DataSource = subDs
nestedRepeater.DataBind()
nestedRepeater.DataMember = subDs.Tables(0).TableName
'We need to specify the DataMember as the dataset has 2 tables.
Dim datarow As DataRow
For Each datarow In subDs.Tables(0).Rows
Dim chart As New dotnetCHARTING.Chart
chart.Type = dotnetCHARTING.ChartType.Combo
chart.DefaultSeries.DefaultElement.Transparency = 35
chart.TempDirectory = "temp"
chart.ChartArea.XAxis.Label.Text = "Customers"
chart.Debug = True
chart.TempDirectory = "temp"
chart.Width = Unit.Parse(420)
chart.Height = Unit.Parse(300)
Dim myView As New DataView(subDs.Tables(0))
myView.RowFilter = String.Format("Measure_ID='{0}'", datarow.Item("Measure_ID"))
chart.Series.Name = "Item sales"
chart.Series.Data = myView
chart.SeriesCollection.Add()
Dim i As Integer
For i = 0 To nestedRepeater.Items.Count - 1
nestedRepeater.Items(i).FindControl("Placeholder1").Controls.Add(chart)
Next
Next datarow
'nestedRepeater.DataBind()
End If
End If
End Sub 'myRepeater_ItemDataBou
====
please help
thanks
|
|
|
|
|
You need to specify the DataMember property before calling the DataBind method:
nestedRepeater.DataSource = subDs
nestedRepeater.DataMember = subDs.Tables(0).TableName
nestedRepeater.DataBind()
'nestedRepeater.DataMember = subDs.Tables(0).TableName
|
|
|
|
|
Hi,
yeah i did try that earlier but it skips every first measureid of a scorecardId dont know why.
|
|
|
|
|
uglyeyes wrote: For Each datarow In subDs.Tables(0).Rows
Dim chart As New dotnetCHARTING.Chart
chart.Type = dotnetCHARTING.ChartType.Combo
chart.DefaultSeries.DefaultElement.Transparency = 35
chart.TempDirectory = "temp"
chart.ChartArea.XAxis.Label.Text = "Customers"
chart.Debug = True
chart.TempDirectory = "temp"
chart.Width = Unit.Parse(420)
chart.Height = Unit.Parse(300)
Dim myView As New DataView(subDs.Tables(0))
myView.RowFilter = String.Format("Measure_ID='{0}'", datarow.Item("Measure_ID"))
chart.Series.Name = "Item sales"
chart.Series.Data = myView
chart.SeriesCollection.Add()
Dim i As Integer
For i = 0 To nestedRepeater.Items.Count - 1
nestedRepeater.Items(i).FindControl("Placeholder1").Controls.Add(chart)
Next
Next datarow
Having a look at this code, I can see that you are creating the chart control inside the fist for statement, but you are adding it to the Controls collection in the second for statement. It means, in the second loop you are using the same chart object to add to the Controls collection. However, there's one important thing that you may not know is that each control only has one parent control, it also means when you add a control to the Controls collection of the new parent control, it will remove the control out of the Controls collection of the current parent control. And as a result of that, the chart control only exists in the last RepeaterItem of the nestedRepeater.
So to work around this problem, you might consider creating the chart control in the second for statement, another option is to create a handler for the ItemDataBound event of the nestedRepeater.
|
|
|
|
|
hi all,
i have problem with javascript. i wrote a function, when i use
|
|
|
|
|
Looks like you are a bit confused between the client side event onclick with the server side event with the same name. If you are using the ASP.NET 2.0, you can check out the OnClientClick event of the button.
|
|
|
|
|
The error was caused by your compiler looking for startClock function in the code-behind file.
If your button is an ASP button, the OnClick is meant to call server-side function (ie. .Net functions). You should use the OnClientClick instead to call your javascript function.
"Democracy is two wolves and a sheep voting on what to have for dinner" - Ross
Edbert
Sydney, Australia
|
|
|
|
|
tanks for your replies,
i am confused because i am very new in asp.net applications . the point of i couldnt understand why this code runs body onload event but returns error on button click event . when i click the button i will start a client side timer and show this to user like a kronometer. also i have something to do on button click event . if i use input(http) button could i use javascript code and click event together?
my english isnt ok so i cant explain what i mean clearly . i hope you can understand
openup your heart and let the sun shine in
|
|
|
|
|
Yes, you can call both Javascript function AND the ASP.Net click event postback using an input button.
If you are using an input button (not ASP.Net Button), then just add <input onclick="return functionName();>"
By returning the value of the function's result, you can choose to return true in your function if you want the input to do postback to the server or false if you don't.
"Democracy is two wolves and a sheep voting on what to have for dinner" - Ross
Edbert
Sydney, Australia
|
|
|
|
|
thanks edbert,
i will try it now
openup your heart and let the sun shine in
|
|
|
|
|
Hi all,
I am passing values from my datagrid to client side javascript function. In that some of the values contains apostrophes or quotes, which is creating error.I guess, this is because of values passed to browser are in ' ' quotes, and it encounter an apostrophes or quotes, that creates an error.
Anybody have some solution of this problem?
Please let me know.
Thank you very much,
NIKI
|
|
|
|
|
Try running the values through System.Web.HttpUtility.HtmlEncode()
|
|
|
|
|
That doesn't affect the apostrophes at all. Apostrophes has no special meaning in HTML, so they are not changed by the HtmlEncode method.
---
b { font-weight: normal; }
|
|
|
|
|
I have the same problem too.
I am a student at BBU in Cambodia.
In major: Information Technology.
This web is so interested.
|
|
|
|
|
Encode the string correctly to be a string value in Javascript:
theString = theString.Replace("\\", "\\\\").Replace("'", "\\'");
---
b { font-weight: normal; }
|
|
|
|