|
I think you shouldnt rely on serverside events. Rather call the method to repopulate the control yourself.
|
|
|
|
|
I agree with you on that.
Please follow the logic here and make a suggestion with code sample if appropiate.
This is a bound dropdownlist..
DataFieldText = EmployeeName
DataFieldValue = EmployeeID
So I Deliver all of the employees to the DropDownList first and that works. All Employees are in the dropdownlist just fine. On the update path in the program, before the first display of the page, I set SelectedValue = EmployeeID, for the employee to be edited. This should cause that employee info to be displayed when the page is presented for the first time and it is not...
Any ideas on why?
Thanks in advance for your assistance..
Chuck...
|
|
|
|
|
Problem resolved..
Appears to have been a combination of programmer error and Data corrupted by the infamous Trailing SPACE. Thanks for your input. Made me go back and go line by line and letter by letter...
|
|
|
|
|
Wow.. Thats great to hear that.
|
|
|
|
|
HI guys i am working with listview conrol and objectdatasource
there is an udate metod wo which my dataobject is bound
bit it does not work, i put a break on updating event of the objectdatasource
but it doest not even break here , delete is working fine ,
update method and delete method taking the type of object.
here is my code
<EditItemTemplate>
<tr style ="background-color:Yellow">
<td class ="Controls">
<asp:LinkButton ID = "EditButton" runat ="server" Text ="Update" CommandName ="Edit"></asp:LinkButton>
<asp:LinkButton ID = "DeleteButton" runat ="server" Text ="Cancel" CommandName ="Cancel"></asp:LinkButton>
</td>
<td class ="Controls">
<asp:TextBox ID = "up_txtupdatecustomerid" runat ="server" Text = '<%#Bind("customerid")%>'></asp:TextBox>
</td>
<td>
<asp:Label ID = "uo_orderid" Text = '<%# Bind("Orderid") %>' runat ="server"> </asp:Label>
</td>
<td>
<asp:TextBox ID ="up_txtshipaddress" runat ="server" Text ='<%#Bind("shipaddress") %>'></asp:TextBox>
</td>
<td>
<asp:TextBox ID ="up_txtshipcity" runat ="server" Text ='<%#Bind("shipcity") %>'></asp:TextBox>
</td>
<td>
<asp:TextBox ID ="up_txtshipcountry" runat ="server" Text ='<%#Bind("shipcountry") %>'></asp:TextBox>
</td>
</tr>
</EditItemTemplate>
Tauseef A Khan
MCP Dotnet framework 2.0.
|
|
|
|
|
|
Hey....
I am very sorry, I didnt saw your last replies. First of all, it seems that your GridView is inside an updatepanel. If this is the case it cant be rendered. It will throw an error like Control 'Grid' of type 'GridView'must be placed inside a form tag with runat=server.
Actually RenderControl looks for Form Element when it Renders. So if you place it as a ContentItem of UpdatePanel , it will not take it as a direct element of HtmlForm. Hence it cant execute RenderControl of the control. So, here is the solution :
//Place this in your code behind to remove the controls. This might be a general function which can be used for any types.
private void ClearElements(Control ctrl)
{
for (int i = ctrl.Controls.Count - 1; i >= 0; i--)
{
ClearElements(ctrl.Controls[i]);
}
if (!(ctrl is TableCell))
{
if (ctrl.GetType().GetProperty("SelectedItem") != null)
{
LiteralControl literal = new LiteralControl();
ctrl.Parent.Controls.Add(literal);
try
{
literal.Text =ctrl.GetType().GetProperty("SelectedItem").GetValue(ctrl, null) as string;
}
catch
{}
ctrl.Parent.Controls.Remove(ctrl);
}
else if (ctrl.GetType().GetProperty("Text") != null)
{
LiteralControl literal = new LiteralControl();
ctrl.Parent.Controls.Add(literal);
literal.Text = ctrl.GetType().GetProperty("Text").GetValue(ctrl, null) as string;
ctrl.Parent.Controls.Remove(ctrl);
}
}
return;
}
//Replace the code snippet in your code just where you wrote :
StringBuilder sb = new StringBuilder();
StringWriter strw = new StringWriter(sb);
HtmlTextWriter htmlw = new HtmlTextWriter(strw);
ClearElements(dgSiparisler);
HtmlForm form = new HtmlForm();
Controls.Add(form);
form.Controls.Add(dgSiparisler);
form.RenderControl(htmlw);
snd.sendconMail("cinersan@hotmail.com", sb.ToString(), "Üyelik Bilgileri");
I think this will solve your issue.
|
|
|
|
|
Dear Abhishek,
you are really a good guy with a lot of patience...
I did not write earlier since I wanted to check the code first. As you said, I suspected from the update panels, and I have already removed it. Therefore I assume I do not need clear element. I checked in both ways anyway.
The thing is, when I render gridview by adding form, program gives, a page can only have one form tag. When I try to render it alone I receive should be within form tag.
I really do not understand.
Thanks alot.
|
|
|
|
|
Yes, But I have used this at least thousand times. It works.
Are you using a simple gridview or any 3rd party gridviews?
I dont know why you are getting this error
|
|
|
|
|
I do not understand either, I send you may aspx page there are no 3rd party element. Could it be caused by a service pack or something like that? Am I supposed to load anything for VS08?
I had a code for exporting data to excel in (VS03) where I did also render a gridview. It does not work either.
It is deadlock..
|
|
|
|
|
Yes.. I think there must be something wrong with the code. It must be working.
If there is no UpdatePanel then only RenderControl does all.
Create a new page, place a gridview with only few elements. And then try to use the same code. See if it exports in your server. If it does, increase the design a bit and gradually move towards the code you made and find out where exactly the problem is.
|
|
|
|
|
Dear Abhishek,
Here are the test you asked for... Completely different project the same result. I know I am asking alor but, could it be possible for you to test it.
Aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test._Default" %>
<!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>
<asp:GridView ID="dgSiparisler" runat="server">
<Columns>
<asp:TemplateField HeaderText="Adet" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblAdet" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "DataAdi")%>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle Width="50px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
cs page:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
namespace Test
{
public partial class _Default : System.Web.UI.Page
{
Class1 u = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
dgSiparisler.DataSource = u.tbl_Al();
dgSiparisler.DataMember = u.tbl_Al().TableName;
dgSiparisler.DataBind();
StringBuilder sb = new StringBuilder();
StringWriter strw = new StringWriter(sb);
HtmlTextWriter htmlw = new HtmlTextWriter(strw);
//ClearElements(dgSiparisler);
HtmlForm form = new HtmlForm();
Controls.Add(form);
form.Controls.Add(dgSiparisler);
form.RenderControl(htmlw);
}
}
}
|
|
|
|
|
Ohh... I am sorry Ersan, as you are about to render the same page which is loading, the server will actually put the gridview inside the Form until it passes the Page_Load. Do this :
Place
<%@ Page ... EnableEventValidation = "false" %>
in the page directive of your page. Now place this in the code behind :
public override void VerifyRenderingInServerForm(Control control)
{
}
Overriding this function will automatically disable the checking of server side form element. And as I have also disabled Event Validation, so any event validation error generation while rendering the Gridview will also be suppressed.
So your server side code will look like :
StringBuilder sb = new StringBuilder();
StringWriter strw = new StringWriter(sb);
HtmlTextWriter htmlw = new HtmlTextWriter(strw);
this.dgSiparisler.RenderControl(htmlw);
string html = sb.ToString();
No need to create a new form element. Just do it, I am sure it will work.
|
|
|
|
|
At last, I managed it... I am saying as if I did something, just copied and pasted .
Thanks alot man.
|
|
|
|
|
You are most welcome ... budd..
|
|
|
|
|
I may be jumping the gun here, but his member page says he is working in Kolkata. At the time you posted this he was probably tucked up in bed! Even if that is not the case, so he helped you a bit yesterday, he has a job to do as well. He will probably get back to you tomorrow, or more likely after the weekend. Have some patience before you repost.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
Ah.. I am proved wrong. He posted even as I was typing. Lucky break eh?
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
Just was busy for the whole day bro...
Got time to help few questions. Actually I reply mostly at night from here.
Cheers.
|
|
|
|
|
Sorry, I am normally patient guy but I was stuck with the problem so I got crazy, I read so many posts in regards to that problem but did not work,
Additionally I was checking his other posts, he was replying other questions and I thought he gave up..
That was the reason to respost..
|
|
|
|
|
Hi Guys
I have a web app, and in this web app I have a list box.
This list box displays file names of word documents that relate to the project which is displayed in the rest of the app.
I have the File names displayed, but the value of the list box is set to the full file path.
My question is, how can I open the documents when a user selects a document and clicks on the "Open Document" button?
I used a ListBox because I'm quite tight on space...
Thank in advance
edit: I'm using C#
oooo, the Jedi's will feel this one....
|
|
|
|
|
Paul Unsworth wrote: My question is, how can I open the documents when a user selects a document and clicks on the "Open Document" button?
You can initiate the File Save As Dialog box on button Click.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
How do you do that? I've tried looking on google, and all I can find are Response.TransmitFile() or Response.WriteFile() which just write the file into the browser just before the page starts.
I was playing around with creating a hyperlink object, and setting the navigate url to the files url, but I cannot find a way to activate it.
I would have used hyperlinks if space and neatness were not so much of an issue...
oooo, the Jedi's will feel this one....
|
|
|
|
|
Paul Unsworth wrote: Response.WriteFile()
That's it, just set the content type first so that the browser knows it's a download, or perhaps a file to be opened in the browser.
Paul Unsworth wrote: I was playing around with creating a hyperlink object, and setting the navigate url to the files url, but I cannot find a way to activate it.
How do you mean, activate ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
By activate, I mean somehow make it think it has been clicked. I was just experimenting with that one. I suppose I was just trying to cheat.
Thank you for your reply.
oooo, the Jedi's will feel this one....
|
|
|
|
|
Use this when user clicks the button to download the file :
Response.Clear();
Response.ContentType="application/word";
Response.AppendHeader("Content-Disposition","attachment; filename=yourfilename.doc");
Response.TransmitFile(serverfilepath);
Response.End();
Cheers.
|
|
|
|