|
ASP.NET is an attempt to put a stateful abstraction ontop of a stateless protocol. When you process a page in ASP.NET is only just got created. As soon as ASP.NET sends the page out to the client it is destroyed. When the client posts back a new page (that looks pretty similar to the last one) is created and you work on the new page. As soon as the processing of that is complete it is destroyed again.
Put simply. It does not and cannot work like a web forms application without significant additional server overhead - and that would place just too much strain on a server if it has to response to any more than a handful of users.
You have to think of ASP.NET applications differently to WinForms applications. They have different sets of constraints.
So, in order to help better we would need to know more about what you are attempting to achieve. What sort of workflow are you dealing with? Then we can advise how best to pass information around.
Man who stand on hill with mouth open wait long time for roast duck to drop in
|
|
|
|
|
|
my work flow scenario is like this; I have a page where I'm capturing event details like event type(e.g wedding) and a button saying "Add Services" which leads to a page("Services.aspx") full of services for the client to choose from. Now, I have another page where there client after logging in ( after sometime) edits the event details. Again I have a button saying "Edit Services" which leads to the same page("Services.aspx"). The idea is to reuse the "services.aspx" page by changing some control texts etc. Under the "Edit Service" button I redirect to the "Services.aspx" and I also need to change the controls of the "Services.aspx" page for them to suit the functionality suggested by the "Edit Services" button, how do I do that? Hope my scenario is clear.Please Help.
ML Lingwati
|
|
|
|
|
You cannot do that in ASP.net, You can create a usercontrol and add it to your hosting page, and to get the values you get expose the properties.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I have a page with a bunch og events for buttons and textchanged.
At page load I want to validate an object I have added to Chash, an if it fails I
want to kill the event that the user has triggerd, something like
protected void Page_Load(object sender, EventArgs e)
{
if (MyChachItem == null)
{
MyAntemPlaceHolder.Visible = true;
ShowMessage(MyAntemPlaceHolder, "Can not continue, please click on the list button and start over.")
}
}
So the user clicks a button (btnSave) on the page, that triggers the btnSave_Click(..) event.
Thus, by the time the MyChachItem is null, as validate at Page_Load, and within that if() I want to kill the btnSave_Click(..) event, so it isn't triggerd.
I think it's possible to use somthing like:
btnSave.Click -= btnSave_Click(..)
But my problem is that the MyHugeWebControl.ascx contains a lot of controlers with different events,
and I was wondering if there where something I could do to kill all the events within that control.
Thanks
Thomas
|
|
|
|
|
Hello All,
I am stuck on a very simple problem and I at a loss at this point. I have checked the message board but could not find a solution to my particular problem so that is why I am coming to you today.
Here goes:
I have a very simple page with a 2 GridViews and a text box (simple master/detail setup). The first Gridview is bound to an SQLDataSource which runs a simple stored procedure and fills the gridview upon it's first load. The gridview has a Selection link on it which when clicked passes an argument to the second gridview which is then populated with the details of the selected row.
Here's the problem, I want to capture another field of the selected row an show it in a textbox. Simple. Not so (for me anyways). In the Page_Load and SelectedIndexChanged event I simply have
'this.TextBox1.Text = this.GridView1.SelectedRow.Cells[2].Text.ToString();'
The SelectedIndexChanged Event doesn't fire before the postback because I get an error in my Page_Load event that there is a NullReferenceException on the Gridview.
Can someone be kind enough to guide me in the right direction on how to cure this ill.
Greatly appreciated.....FF
|
|
|
|
|
Well, writing the above code in page load doesn't make sense. When the page loads first time, SelectedRow will be NULL . Is this throwing error when you use it in the selected index changed event?
|
|
|
|
|
Well I hope I am not the only one who has ever done this, I have faith that I am not.
But, I thought about just what you replied Navaneeth, and realized the code in the page_load didn't make sense. So I removed it but the SelectedIndexChanged event never fired. So I (just now) reviewed the event. I works now because I put the code in the GridView1 event as opposed to the "GridView2" event.
Thanks for your reply and I shall bow out humbly now...
|
|
|
|
|
At the time when the page gets loaded, do you think that the GridView1 has any selected row? The problem lies here.
There is no foolish question, there is no final answer...
|
|
|
|
|
ffowler wrote: In the Page_Load and SelectedIndexChanged event I simply have
'this.TextBox1.Text = this.GridView1.SelectedRow.Cells[2].Text.ToString();'
The SelectedIndexChanged Event doesn't fire before the postback because I get an error in my Page_Load event that there is a NullReferenceException on the Gridview.
Check Selected Row index for null before the statement.
|
|
|
|
|
Hi,
I have table inside server controls like Text box and dropdown, i want to clear all controls inside the Table, instead of giving all controls name. i want to use the Table name only. if any one knows plz reply me..
thanks...
|
|
|
|
|
Your question is quite ambiguous to me. What do you mean by clearing all controls? Do you want to remove all controls that are placed inside the tables?
There is no foolish question, there is no final answer...
|
|
|
|
|
ok i will clearly explain,
inside table three rows having 3 text boxes. i want to clear the values on the text box from javascript. instead of taking 3 text box client can i take table clientid,
Ex:
document.getelementid("<%= textbox1.ClientID%>").value==""; this is obviously normal way to clear.
my intension is , i want to use the table id to calear all text of controls inside the table.
i hope now u will understand my problem
..
|
|
|
|
|
kanadoss wrote: document.getelementid("<%= textbox1.ClientID%>").value==""; this is obviously normal way to clear.
No.
kanadoss wrote: my intension is , i want to use the table id to calear all text of controls inside the table.
Get the tables object
var tableObj = document.getelementid("<%= textbox1.ClientID%>")
Use getElementsByTagName to get all the input controls. Something like
var controls = tableObj.getElementsByTagName("input")
controls variable will have all the input objects under that table. Now iterate over the elements and set it's value. BTW, why do you want to do this using only the table id when you can use the text box id directly. I guess that will be more reliable.
|
|
|
|
|
Oh yeah, it is quite clear now. I think, what would you intend to do is not really possible? It doesn't matter whether controls are parent or child; their control id at the render time always differ and those are unique. So I don't think that it is possible to set properties of child controls by using parent control. But you can iterate through the control collections by running a loop and check if control name starts with the parent control name then set its value to empty. But you have to validate also.
There is no foolish question, there is no final answer...
|
|
|
|
|
Can any one help me
How to create server control at run time in ASP.Net 2.0
|
|
|
|
|
|
Amit Patel1985 wrote: How to create server control at run time in ASP.Net 2.0
Which control you want to create ? Create the object of that control class, set the properties and add them to the page.
Be careful when you creating control at runtime. You should take care of view state of the control and its depends in which event you are creating them.
|
|
|
|
|
Hi,
I have to generate a word document dynamically in .Net.
I have to write the contents of the GridView to the Word document.
I am able to do all but,the problem is i have to save the file automatically to a particular folder than saving the File via the FileDialog box.
Can anyone please tell me that how to store the word file automatically to a particular location?
I have given the code below.
string attachment = "attachment; filename=" + strFilePath;
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-word";
StringWriter sWriter = new StringWriter();
HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter);
gvRCA.RenderControl(htwWriter);
Response.Write(sWriter.ToString());
Response.End();
Yazhini
|
|
|
|
|
YazhiniP wrote: the problem is i have to save the file automatically to a particular folder than saving the File via the FileDialog box.
You should never tell the client yes, unless you know enough about what you're doing, to know that it's possible. In this case, it's not possible. Imagine if it was, if every website could just put files into your file system without asking you first.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
ok...I dropped the idea of using Response object.I tried using FileStream and StreamWriter.but,how to pass the GridView object to the StreamWriter?
FileStream fs = File.Create(path);
fs.Close();
StreamWriter sw = new StreamWriter(path);
StringWriter sWriter = new StringWriter();
HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter);
gvRCA.RenderControl(htwWriter);
sw.Write(htwWriter);
sw.Close();
The above code writes only System.Web.UI.HtmlTextWriter to the word file.
I am beginner in .Net and i dont know a lot.
Do u have any idea on how to do this?.
Thanks in advance...
Yazhini
|
|
|
|
|
Dim img As FileUpload = CType(imgUpload, FileUpload)
Dim imgByte As Byte() = Nothing
Dim imgtype As String = Nothing
If img.HasFile AndAlso Not img.PostedFile Is Nothing Then
'To create a PostedFile
Dim File As HttpPostedFile = imgUpload.PostedFile
'Create byte Array with file len
imgByte = New Byte(File.ContentLength - 1) {}
imgtype = New String(File.ContentType)
'force the control to load data in array
File.InputStream.Read(imgByte, 0, File.ContentLength)
End If
' Insert the employee name and image into db
c.Open()
Dim sql As String = "INSERT INTO tblImg (img_type, img_stream)VALUES (@img_type,@img_stream) "
Dim cmd As SqlCommand = New SqlCommand(sql, c)
cmd.Parameters.AddWithValue("@img_type", imgtype)
cmd.Parameters.AddWithValue("img_stream", imgByte)
Dim id As Integer = Convert.ToInt32(cmd.ExecuteScalar())
lblResult.Text = String.Format("Employee ID is {0}", id)
|
|
|
|
|
jigneshp25 wrote: cmd.Parameters.AddWithValue("@img_type", imgtype)
cmd.Parameters.AddWithValue("img_stream", imgByte)
What do you notice about the two parameters you're pasing in ? Yes, one has an @ and the other does not. Hence the problem.
It pays to read the error message and then assume that it's true.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
jigneshp25 wrote: cmd.Parameters.AddWithValue("@img_type", imgtype)
cmd.Parameters.AddWithValue("img_stream", imgByte)
where is @ for the img_stream ? When your debugger showing the error , then click on the error, debugger redirect you to the correct line.
|
|
|
|
|
Hello........I m decveloping an application in which i hav to create data table dynamically......i hav written the code the but getting the error....plz help me...code is below:-
Dim objDT As New System.Data.DataTable
Dim objDR As System.Data.DataRow
Private Sub Page_Load(ByVal s As Object, ByVal e As EventArgs)
If Not IsPostBack Then
makeCart()
End If
End Sub
Function makeCart()
objDT = New System.Data.DataTable("Cart")
objDT.Columns.Add("ID", GetType(Integer))
objDT.Columns("ID").AutoIncrement = True
objDT.Columns("ID").AutoIncrementSeed = 1
objDT.Columns.Add("Quantity", GetType(Integer))
objDT.Columns.Add("Product", GetType(String))
objDT.Columns.Add("Cost", GetType(Decimal))
Session("Cart") = objDT
End Function
Sub Delete_Item(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
objDT = Session("Cart")
objDT.Rows(e.Item.ItemIndex).Delete()
Session("Cart") = objDT
dg.DataSource = objDT
dg.DataBind()
lblTotal.Text = "$" & GetItemTotal()
End Sub
Sub AddToCart(ByVal s As Object, ByVal e As EventArgs)
objDT = Session("Cart")
Dim Product = ddlProducts.SelectedItem.Text
objDR = objDT.NewRow(GETTING ERROR IN THIS LINE)
'Error is same which is written in Subject line
objDR("Quantity") = txtQuantity.Text
objDR("Product") = ddlProducts.SelectedItem.Text
objDR("Cost") = Decimal.Parse(ddlProducts.SelectedItem.Value)
objDT.Rows.Add(objDR)
Session("Cart") = objDT
dg.DataSource = objDT
dg.DataBind()
Dim blnMatch As Boolean = False
For Each Me.objDR In objDT.Rows
If objDR("Product") = Product Then
objDR("Quantity") += txtQuantity.Text
blnMatch = True
Exit For
End If
Next
If Not blnMatch Then
objDR = objDT.NewRow
objDR("Quantity") = Int32.Parse(txtQuantity.Text)
objDR("Product") = ddlProducts.SelectedItem.Text
objDR("Cost") = Decimal.Parse(ddlProducts.SelectedItem.Value)
objDT.Rows.Add(objDR)
End If
lblTotal.Text = "$" & GetItemTotal()
End Sub
Function GetItemTotal() As Decimal
Dim intCounter As Integer
Dim decRunningTotal As Decimal
For intCounter = 0 To objDT.Rows.Count - -1
objDR = objDT.Rows(intCounter)
decRunningTotal += (objDR("Cost") * objDR("Quantity"))
Next
Return decRunningTotal
End Function
</script>
|
|
|
|