|
thanx for ur reply..
my DDL gets loaded with the items on pageload. so the DDL has items in it.. the If condition that im using is working fine if the item retrieved from the database is present in my DDL, it throws an exception only if that item is not present in my DDL...
if(ddl_Benef.Items.FindByValue(myDr["BenefName"].ToString().Trim()).Value == myDr["BenefName"].ToString())
{
ddl_Benef.Items.FindByValue(myDr["BenefName"].ToString().Trim()).Selected=true;
}
else
{
ddl_Benef.Items.FindByText("Select an option").Selected=true;
}
Im not sure if my condition in the if statement is properly framed or not...
plz advise..
Thanx in advance,
Tash..
|
|
|
|
|
IMO, you should first check whether your condition in if is returning or not.
Try like this:
if(ddl_Benef.Items.FindByValue(myDr["BenefName"].ToString().Trim()) != null)
{
if(ddl_Benef.Items.FindByValue(myDr["BenefName"].ToString().Trim()).Value == myDr["BenefName"].ToString()) { ddl_Benef.Items.FindByValue(myDr["BenefName"].ToString().Trim()).Selected=true; } else
{ ddl_Benef.Items.FindByText("Select an option").Selected=true; }
}
else
{
}
If that value is not null, then proceed. Otherwise, set your default option as selected
|
|
|
|
|
|
I am creating a ASP.Net server control to manage locations. The control is a composite control containing several text-boxes, labels, and a link button. I use the AJAX Control Toolkit to provide a modal popup which contains a Bing map. All the Javascript is in its own file and used as an embedded web resource.
The link button is what opens the modal popup. It also needs to call a Javascript function that initializes the Bing map (onclick = "GetMap();"). There are instances when this server control is placed within an Update Panel (and there is no way to avoid this). When in an Update Panel the link button loses its onclick event. I understand that this is because during an async postback the portion of the DOM that defines the content of the Update Panel is thrown out and reinitialized, resulting in the event breaking. When the control is not in an Update Panel everything works as intended.
I have tried registering events on Page.Load and Page.Init, like so:
link_FindLocation = new LinkButton();
link_FindLocation.OnClientClick = "GetMap();";
Page.Load += delegate(object sender, EventArgs args)
{
link_FindLocation.OnClientClick = "GetMap();";
};
I have also tried flat out writing the function call to the page:
link_FindLocation = new LinkButton();
link_FindLocation.OnClientClick = "GetMap();";
link_FindLocation.Click += delegate(object sender, EventArgs args)
{
Page.Response.Write("<script type = \"text/javascript\">GetMap();</script>");
};
I have put breakpoints on the lines inside each delegate and they do not get hit. I am not aware of any special way to register events of a composite control's child control or the Page.Load/Page.Init events when being done inside a server control. Is there some special way to register these events? (Note: Both those code blocks above are in my CreateChildControls() method)
Below is the GetMap() Javascript function. As you can see it is pretty straight forward.
var map;
function GetMap()
{
if (map != null)
{
map.Dispose();
}
map = new VEMap('map'); map.SetDashboardSize(VEDashboardSize.Tiny);
map.LoadMap(new VELatLong(42.869925, -78.681335), 10);
map.Resize('440px', '360px');
map.SetZoomLevel(12);
}
Does anyone have a solution to Javascript events breaking after an async postback that can be applied to a server control? Everything needs to be done within the server control itself and not in the page that is using the control.
|
|
|
|
|
Jake Slack wrote: The link button is what opens the modal popup. It also needs to call a Javascript function
Wouldn't be nice if the modal popup contained code to call
a Javascript function ?
|
|
|
|
|
If you are referring to the OnOkScript and OnCancelScript properties of the ModalPopupExtender then I cannot use them. I need the Javascript to run when the ModalPopupExtender 's TargetControl is clicked, not the Ok or Cancel buttons. Also, since the ModalPopupExtender does have to live within Update Panels and still function, both OnOkScript and OnCancelScript (along with several other unrelated things) are inherently broken.
If you are referring to something else, please explain.
Thanks
|
|
|
|
|
Actually I was thinking of calling the javascript
from the modal on initiation not by button click.
|
|
|
|
|
Hi,
i have a problem retrieving a control that has been added at runtime into the place holder... Please provide help...
<telerik:GridTemplateColumn HeaderText="Description" SortExpression="ProductName" UniqueName="ProductName2">
<HeaderStyle HorizontalAlign="center" />
<ItemStyle HorizontalAlign="Left" Width="700px" />
<ItemTemplate>
<table style="border:0px;" >
<tr >
<td style="border:0px;">
<asp:Label id = "lblProductDescription" runat = "server" Text = '<%# Eval("ProductName") %>'></asp:Label>
</td>
</tr>
<tr >
<td style="border:0px;" ID ="tdAttributes" runat = "server">
<asp:PlaceHolder id = "placeHolderAttributes" runat = "server" Visible = "false"></asp:PlaceHolder>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:GridTemplateColumn>
Control is added in ItemDataBound as. This code works,
</pre>
'htmltable,row and cells are declared
Select Case controltype
Case ControlType.TEXTBOX 'Constants declared
Dim textBox As Telerik.Web.UI.RadTextBox = New Telerik.Web.UI.RadTextBox
textBox.ID = "MYCONTROL"
tableCell.Controls.Add(textBox )
Case ControlType.TEXTAREA
Dim textBox As Telerik.Web.UI.RadTextBox = New Telerik.Web.UI.RadTextBox
textBox.ID = "MYCONTROL"
tableCell.Controls.Add(textBox )
Case GlobalControls.UCFormFields.FormFieldTypes.CHECKBOX
Case GlobalControls.UCFormFields.FormFieldTypes.DROPDOWNLIST
End Select
thisHtmlTable.Rows.Insert(0, thisTableRow)
thisTableRow.Cells.Add(tableCell)
thisTableRow.Visible = True
thisHtmlTable.Rows.Insert(thisHtmlTable.Rows.Count, thisTableRow)
Dim placeHolder As PlaceHolder
placeHolder = gridItem.FindControl("placeHolderAttributes")
placeHolder.Controls.Add(thisHtmlTable)
placeHolder.Visible = True
In item command , i want to retrieve the control, i can switch between the controls if i retrieve the placeholder... my problem is that in itemcommand, i can retrieve the Placeholder but when i try placeholder.controls.count, it returns 0 and cannot retrieve any control
i am trying the following code in itemcommand
item("ProductName2").FindControl("placeHolderAttributes").Findcontrol("MYCONTROL") 'this throws an error
'also tried
item("ProductName2").FindControl("placeHolderAttributes").controls.count 'this shows 0
Please provide help...
Thanks!!!
Mark
|
|
|
|
|
Hi Mark,
before the execution of the ItemCommand , you must redraw the grid as you are creating dynamic controls on ItemDataBound.
Regards,
Jamil
|
|
|
|
|
Hi,
Thanks for replying.
I am not sure on how to redraw the grid. i mean, i am not sure on which event to use for creating the controls, so that the controls are available for itemcommand.
Can u please provide a bit more detail.
Thanks again.
Mark
|
|
|
|
|
Hey Friends, I have found one new website for free online test and interview questions http://www.smarttestguru.com/[^]
Do visit its useful.
Nikhil Bandekar
Mumbai,
India
|
|
|
|
|
You might be trying to help but your thread is against CodeProject rules. It looks like you are advertising a website of yours or your friend. Kindly avoid the same.
P.S.: Based on your profile and last activity done by you in 2007, it most certainly looks like a sudden advertising message from you!
|
|
|
|
|
Hi, all,
I have an empty data message if there is no any records available. My problem is that the message is always put at top left, even I already HorizontalAlign="Center" and VerticalAlign="Middle".
Can you tell me how can I put it in the middle of Gridview?
Thanks
|
|
|
|
|
Use the CSSClass property to assign a style. You will have much better control over appearance.
|
|
|
|
|
I am using .Net Framework 3.5, VS2008, C#, and ASP.Net
I cannot access a class that I defined in a class library project from an aspx.cs code-behind file. I am using the namespace "BusinessServices" in the class library, but when I try to use the namespace in the aspx.cs codebehind file (i.e "using BusinessServices") I get the error "The type or namespace name 'BusinessServices' could not be found (are you missing a using directive or an assembly reference?)".
I added a reference to the BusinessServices.DLL from the Add Reference Project tab, and I even tried to do it by browsing to the DLL. Nothing helps.
I am not sure what step I am missing.
Thanks.
Adam
|
|
|
|
|
Hi,
maybe the namespace you wish to use has no public classes/elements. Check, if the class you wanna
use is public.
Other than that, i suggest you create a simple sample project and try to reference the assembly and use the namespace there. Maybe this way you can exclude possible "maybe-problems" or provide us your sample.
Good Luck
|
|
|
|
|
Do you have an assembly directive similar to this ...
<%@ Assembly Name="assemblyname" %>
<%@ Assembly Src="pathname" %>
|
|
|
|
|
Hello everybody,
In my code i m checking list item is selected or not. if it is selected i m calling a function. however i m not getting lstname.Item[i].selecteditem = true till i select one of the item from list.
for(i=1;i<=lstname.items.count;i++)
{
if(lstname.Item[i].selected)
{
gotosomefunction();
}
}
Thanking you in advance...
modified on Tuesday, April 27, 2010 1:23 PM
|
|
|
|
|
sandympatil wrote: i m not getting lstname.Item[i].selecteditem = true till i select one of the item from list.
Well, dah! Do you expect ASP.NET to magically read your mind and know what item you intend to select
Also, you should use lstname.Item[i].selected not lstname.Item[i].selecteditem
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Maybe you can rephrase your question and provide a working codeblock?
I'm trying to understand the problem, but unfortunately, i'm failing.
In general, if indeces of selected items cannot be retrieved, i would double check
the databinding on that listbox. if the listbox is rebound on that postback, you may lose
the selected item indeces.
try putting your databinding in an "if(!IsPostback)" block - if youre binding of course.
Good Luck
|
|
|
|
|
sandympatil wrote: however i m not getting lstname.Item[i].selecteditem = true till i select one of the item from list.
So whats wrong in that.
|
|
|
|
|
Hi,
I am using ASP.net 2.0 and C# as code behind , there is a requirement where i need to convert a string value to PDF, if anyone has solution please let me know, appreciate your help. This is very urgent need.
Thanks
ashish
|
|
|
|
|
Download SharpPDF, and check out the tutorials[^]
I are Troll
|
|
|
|
|
Hi everybody.
I need some help with a problem.
Can anybody say what's wrong with my script?
When executing, IE says that there is an error on the line with the __dopostback.
I do not have knowledge on javascript, but I copied the code and made it work sometimes.
Right now, I'm going crazy with it. Thanks in advance.
<script language="javascript">
var sFeatures='dialogWidth: 500px;dialogHeight: 200px;status:no;scroll:no';
var Resp = window.showModalDialog('PopUpMsg.aspx', window,sFeatures);
if (Resp == True)
{
__doPostBack('btnBorrar','1');
}
</script>
It is supposed to show a modal window called PopUpmsg.aspx, where I'll answer Yes or No. That works fine. But after answering, I need to reload the page, and the postback does not seem to work.
|
|
|
|
|