|
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>
|
|
|
|
|
I suspect that objDT is null. Have you stepped through the code, to see if this is so ? How about writing code that checks for nulls and doesn't blow up ?
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
|
|
|
|
|
Why don't use "Session("Cart")" variable which already stored the data table. objDT is returning null. Typecast the session variable into a datatable object.
There is no foolish question, there is no final answer...
|
|
|
|
|
ankurdsharma wrote: objDT = New System.Data.DataTable("Cart")
ankurdsharma wrote: objDT = Session("Cart")
Did you check the Session variable for null ?
Where is the Type Cast ?
ankurdsharma wrote: objDR = objDT.NewRow(GETTING ERROR IN THIS LINE)
'Error is same which is written in Subject line
So that the reason that you are getting error here.
|
|
|
|
|
How to Add the BindingManager to the tool box in asp.net
modified on Friday, June 12, 2009 7:21 AM
|
|
|
|
|
Hi Everybody
I need to fetch most visited articles from my News module...Please give me some idea
Thanks in advance
Ramkumar
|
|
|
|
|
What have you tried ? What seems the obvious way to do that ? Do you store a counter for how often a page is visited ? If not, how do you expect to do this ? If so, it suddenly becomes trivial, right ?
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
|
|
|
|
|
How are you going to track that totally depends on your strategy and business requirement? But stating from the basic, you can probably create a column called "viewcount" on any of the table where you are storing all articles. In the page load and under if(!IsPostBack) just write down the code to update the "viewcount" flag by 1. Just a basic idea which may help you.
Regards
Saanj
There is no foolish question, there is no final answer...
|
|
|
|
|
You could always use something like Google Analytics - It takes a few minutes to set up as it just requires that you add some javascript to your page.
Alternatively, you probably want to create a database table and each time you have to render a news article INSERT a row in the database to say what article was rendered and any other information you want to store with that (e.g. a date/time, the UrlReferrer, etc. etc.)
To get the most visited articles all you need to do is count each time an article appears in the database.
Man who stand on hill with mouth open wait long time for roast duck to drop in
|
|
|
|
|
Hi all,
I want to redirect the page after alert box is clicked . but the page redirects before the alert was called Wat to do..
|
|
|
|
|
can you paste the code that is redirecting the page and displaying alert
|
|
|
|
|
You should use javascript,fire function name from your control.
function ShowAlert()
{
alert('You will redirect in another page');
window.open(' yoururladdress/pagename.aspx');
}
onclick="ShowAlert()"
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
This is wat i used but the page is redirected without waiting for alert box.
|
|
|
|
|
Which control you are using to redirect in another page?
If you are using button then use property
OnClientClick="ShowAlert(); return false;"
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
I have validation one the control.Now validation is not working..
|
|
|
|
|
Your core problem is that you think we're mind readers. Your code is broken. We can't fix it without seeing it.
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
|
|
|
|