|
|
Hi!
I ran into a bit of a problem. I have managed to successfully Create a row of 7 textboxes in a Table at runtime. I used the CalendarExtender on the first Textbox and it works perfect. The trouble begins when I click the "ADD" button to create a new row of 7 Textboxes. I have set the calendarExtender targetId = "txtCalendar" + j meaning that the targetID is txtCalendar0. When I hit the "ADD" button to create a second row I get the error that the TargetId has to be unique.
I understand that I am currently targeting the txtCalendar0 textbox and that works but when I click add to create a second row the first textbox is named txtcalendar0 as well.
Any suggestions on how to get around this?? Please let me know if I should post the piece of code for this.
Thank you!
Illegal Operation
|
|
|
|
|
How are you generating the IDs? Post the code.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Here is the code as it works now. Everytime you click the add button it should just duplicate the existing row.
private int numOfRows = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GenerateTable(numOfRows);
}
}
private void GenerateTable(int numOfRows)
{
Table tblTimesheet = new Table();
tblTimesheet.ID = "tblTimesheet";
placeHolder.Controls.Add(tblTimesheet);
const int colsCount = 12;
for (int i = 0; i < numOfRows; i++)
{
TableRow HeaderRow = new TableRow();
TableRow newRow = new TableRow();
for (int j = 0; j < colsCount; j++)
{
TableCell newCell = new TableCell();
newCell.HorizontalAlign = HorizontalAlign.Center;
TextBox txtWeekday = new TextBox();
txtWeekday.ID = "txtWeekday" + j;
txtWeekday.Width = 80;
CheckBox chkLunchCrib = new CheckBox();
chkLunchCrib.ID = "chkLunchCrib" + j;
chkLunchCrib.Checked = false;
if (txtWeekday.ID == "txtWeekday11" || txtWeekday.ID == "txtWeekday10" || txtWeekday.ID == "txtWeekday9")
{
txtWeekday.Visible = false;
}
if (chkLunchCrib.ID == "chkLunchCrib0" || chkLunchCrib.ID == "chkLunchCrib1" || chkLunchCrib.ID == "chkLunchCrib2" || chkLunchCrib.ID == "chkLunchCrib3" || chkLunchCrib.ID == "chkLunchCrib4" || chkLunchCrib.ID == "chkLunchCrib5" || chkLunchCrib.ID == "chkLunchCrib6" || chkLunchCrib.ID == "chkLunchCrib7" || chkLunchCrib.ID == "chkLunchCrib8")
{
chkLunchCrib.Visible = false;
}
#region Date Selection.
TextBox txtCalendar = new TextBox();
txtCalendar.ID = "txtCalendar" + j;
txtCalendar.Width = 155;
txtCalendar.Text = DateTime.Today.ToShortDateString();
ImageButton imgbtnCalendar = new ImageButton();
imgbtnCalendar.ID = "imgbtnCalendar";
imgbtnCalendar.ImageUrl = "~/Resources/Calendar_scheduleHS.png";
imgbtnCalendar.ImageAlign = ImageAlign.AbsMiddle;
AjaxControlToolkit.CalendarExtender ajaxCalExt = new AjaxControlToolkit.CalendarExtender();
ajaxCalExt.ID = "ajaxCalExt";
ajaxCalExt.TargetControlID = "txtCalendar" + j;
ajaxCalExt.PopupButtonID = "imgbtnCalendar";
#endregion
if (txtCalendar.ID == "txtCalendar0" && txtWeekday.ID == "txtWeekday0")
{
newCell.Controls.Add(txtCalendar);
newCell.Controls.Add(imgbtnCalendar);
newCell.Controls.Add(ajaxCalExt);
txtWeekday.Visible = false;
}
newCell.Controls.Add(txtWeekday);
newCell.Controls.Add(chkLunchCrib);
newRow.Cells.Add(newCell);
}
tblTimesheet.Rows.Add(HeaderRow);
tblTimesheet.Rows.Add(newRow);
}
numOfRows++;
ViewState["RowsCount"] = numOfRows;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
if (ViewState["RowsCount"] != null)
{
numOfRows = Convert.ToInt32(ViewState["RowsCount"].ToString());
GenerateTable(numOfRows);
}
}
Illegal Operation
|
|
|
|
|
Illegal Operation wrote: for (int i = 0; i < numOfRows; i++)
Above loop will run number of times equal to the value of i. In this case
Illegal Operation wrote: "txtCalendar" + j;
will create the multiple target control id for ajaxCalExt.
You may try this, ajaxCalExt.TargetControlID = "txtCalendar" + j.ToString() + i.ToString();
|
|
|
|
|
Illegal Operation wrote: private void GenerateTable(int numOfRows)
{
Table tblTimesheet = new Table();
tblTimesheet.ID = "tblTimesheet";
placeHolder.Controls.Add(tblTimesheet);
.
.
.
As per the above lines, the Table tblTimesheet would be added to the place holder as many times as you click the Add row button.
You would need to change the logic to first check if the place holder already has a the desired table and based on availability you have to either create a new instance or get an handle to the existing instance and add rows. To do this you have to set the runat property of the table that you create to "server" so that the table is visible on the server after postback. You would also have to change the logic to add rows based on the above availability check.
Alternately you can clear the control array before you add the new table, but if you decide to do so then you'll have to ensure that you copy the data from the existing table's textboxes to the new table's textboxes.
For the replication logic for the date textbox you can use the logic suggested by arun$aini. In fact it would be advisable to do it for all the controls that you add to the table.
I assume you need to get the data from the textboxes/checkboxes on some submit button click. For that to happen you need to set the runat property of all the dynamically created controls too.
|
|
|
|
|
Hi,
I am having two iframes on a page, the top one contains a select box and the bottom one holds a aspx page depending on the selection of list item in the select box. So, it should always reload the bottom iframe whnever an item is changed in the selectbox and for that i am using reload() to reload the aspx page.
And the expected behavior is it should get refreshed (i.e. no postback)
But the acutal behavior happening in my case is its throwing this "to display the webpage again the IE needs to resend the information back ..." alert and when click on cancel or retry buttons on the alert its now doing a postback which is not expected.
If anybody have any clues, please post them
|
|
|
|
|
Please show me how you are doing the refresh operation.
|
|
|
|
|
this is how I am reloading the aspx in that frame.
top.pageContainer.location.reload()
One more thing, the problem is seen if there were any postbacks registered in the aspx page. I mean, it works as expected(reloads the page without postback) when there are no postbacks registered on the aspx page. But once a postback event is done on the aspx and try to reload the page it throws that message and postbacks. I thnk this is because, its caching that postback event.
But for now, i found the hack...
instead of doing a location.reload() i am doing this
top.pageContainer.location = top.pageContainer.location.href
as pointing to a new url (but pointing the same one)
this one solves the problem for now.
|
|
|
|
|
Hi,
I am working on a Asp.net application in this on button click I need to open a URL in a new browser window of height=300 and width=500.
If anyone have any idea to do this please reply me.
Thanks in Advance
|
|
|
|
|
|
you can use java script to do this.
|
|
|
|
|
use
javascript:window.open('url')
|
|
|
|
|
You can even use ASP.Net's LinkButton and set its property target to _blank
Please don't forget to mark 'Good Answer', if you find it really a good one!
Kashif
|
|
|
|
|
Of course, when you're using a hyperlink or a linkbutton you can just set the target, and of course as others have mentioned, there's always javascript. That said, if you really need to use a button, or any other scenario where you want a new window to be fired up from an event handler in your code, this trick might be helpful.
On your page (or on your master page) find the form by its ID:
<br />
HtmlForm frm = Page.FindControl("YourFormID") as HtmlForm;<br />
if (null != frm)<br />
{<br />
frm.Target = "_blank";<br />
}<br />
Hope this helps -
|
|
|
|
|
Hi,
I am exporting some values into excelsheet.
But when i open the excelsheet that time one column is showing some junk data but if i change the format of the cell from the excel then it is showing the correct data.
I implemented export to excel using c# language.
Any idea, how to set the cell format or any other way to show the data correctly with out changing the cell format from the excel.
Thanks In Advance for better solution.
modified on Wednesday, December 2, 2009 6:55 AM
|
|
|
|
|
Assuming you are using excel objects to generate the excel file, you can use the "NumberFormat" property of the desired cell to what ever format you want.
To know what format text to apply, just open an excel sheet, start recording a macro, and set the desired format. You can get the format string from the macro code.
|
|
|
|
|
Junk character means is it something with #### ?
If this is so, it is because the whole data cant be shown because of insufficient space.
It is normal and dont worry, the data is correctly there.
If this is not the case, I think there is some problem. I need to know how are you exporting data to excel then. Is it using OleDb or InterOp ?
|
|
|
|
|
how you're exporting to excel?
Please don't forget to mark 'Good Answer', if you find it really a good one!
Kashif
|
|
|
|
|
I'm working on "forgot password" query in login form in the asp.net. And When I debug the program and write the username in the textbox, click on the submit button , there generates an error "The server rejected one or more recipient addresses. The server response was: 501 5.5.4 Invalid Address"
plz tell me hot to remove that error
|
|
|
|
|
vinci007 wrote: "The server rejected one or more recipient addresses. The server response was: 501 5.5.4 Invalid Address"
The error clearly says that the address you are providing is wrong.
Where is your code for sending mail ?
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
ok..I have taken one textbox in the form ..Coding is:
protected void btnSubmit_Click(object sender, EventArgs e)
{
string qry = "Server=.\\sqlexpress; Initial Catalog=dbLogin; Integrated Security=true";
SqlDataAdapter adp = new SqlDataAdapter("Select Email,(select password from tbLogin where UserName = 'Rahul') as password FROM Details WHERE UserName= 'Rahul'", qry);
DataSet ds = new DataSet();
adp.Fill(ds);
string mailQry = ds.Tables[0].Rows[0]["Email"].ToString();
string pwdQry = ds.Tables[0].Rows[0]["password"].ToString();
MailMessage mailObj = new MailMessage();
mailObj.To = "'" + mailQry + "'";
mailObj.From = "hradmin@ionsoftnet.com";
mailObj.Subject = "Your Password";
mailObj.Body = "'" + pwdQry + "' ";
SmtpMail.SmtpServer = "mail.ionsoftnet.com";
SmtpMail.Send(mailObj);
}
Note: My server address is absolutely right .
what could be the other problem?
|
|
|
|
|
vinci007 wrote: mailObj.To = "'" + mailQry + "'";
What is the value for MailQry ? Try to debug it .
You may also look into this :
http://support.microsoft.com/kb/276866[^]
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
"mailQry" retreives the value from the database. its taking the value as "rahul@ionsoftnet.com" when i'm entering the value "Rahul" in the textBox "txtfrgot"..
|
|
|
|
|
I have created a web service, when i execute the code from Editor in debug mode it works fine without any issue.
But when i run the same code from the Virtual Directory
(http://localhost/service) and try to execute the function, it gives error 500.
Can you please help in resolving the Issue
|
|
|
|