I'm trying to have a RadNotification pop up in an event handler in my C# code. I tried something similar to this:
The markup,
<asp:button> ... OnClick="OnClick"</asp:button>
and the CodeBehind,
protected void OnClick(...) {
new RadNotification().Show("Some text");
}
But that doesn't work. The Telerik documentation doesn't seem to have much info on creating these notifications in a CodeBehind.
Thanks
This works for me...
Markup
<telerik:RadNotification ID="RadNotification1" runat="server" VisibleOnPageLoad="False" Width="300px" Height="100px" EnableRoundedCorners="true" EnableShadow="True" Title="My Notification" Position="Center" TitleIcon="none" />
<telerik:RadButton runat="server" ID="MyBtn" Text="Show Notification" OnClick="MyBtn_Click" />
Code Behind
protected void MyBtn_Click(object sender, EventArgs e)
{
RadNotification1.Show("Some text");
}
Modify the RadNotification attributes as necessary.
Cheers
When creating controls dynamically in ASP.NET WebForms, you must:
add them to the form (or a container in it), which you do not. It is also adviseable that you provide them with IDs
re-create them upon subsequent postbacks if they are going to be needed
This is not something specific to the Telerik controls, but it also applies to any control. Try adding a textbos with a preset text like this to see the problem.
Thus, Scotty's answer where the notification is simply declared in the markup is perhaps the most straightforward solution.
Related
I have a hyperlink in ASPxScheduler VerticalAppointmentTemplate. I want to access the same in runtime code behind.
My Aspx code is as below:
<dxwschs:ASPxScheduler ID="CalendarView" runat="server" Width="100%" ActiveViewType="Day">
<ResourceNavigator EnableIncreaseDecrease="false" />
<Views>
<DayView ResourcesPerPage="1">
<WorkTime Start="08:00:00" End="17:00:00" />
<Templates>
<VerticalAppointmentTemplate>
<asp:HyperLink ID="CalendarViewLink" runat="server" Text="View"></asp:HyperLink>
</VerticalAppointmentTemplate>
</Templates>
</DayView>
</Views>
<OptionsBehavior ShowViewSelector="false" />
<Storage EnableReminders="false" />
</dxwschs:ASPxScheduler>
I have tried using various ways like
ASPxHyperLink calendarViewLink = (ASPxHyperLink)CalendarView.FindControl("CalendarViewLink");//Method 1
ASPxHyperLink calendarViewLink = (ASPxHyperLink)Page.FindControl("CalendarViewLink");//Method 2
ASPxHyperLink calendarViewLink = (ASPxHyperLink)updatepanelid1.FindControl("CalendarViewLink");//Method 3
also tried using rendered id of same link.
ASPxHyperLink calendarViewLink = (ASPxHyperLink)CalendarView.FindControl("ctl00_ContentPlaceHolder1_ContentControl_CalendarView_aptsBlock_AptTemplateContainer700_CalendarViewLink");
Please help me out for find the control. I have to bind the NavigateUrl at runtime.
Are you trying to bind the link during the DataBind event of the ASPxScheduler?
I'm sure there must be a way to get a reference to your link using FindControl method however you will have traverse the whole hierarchy of controls (ASPxScheduler->Views->DayView) to get to the parent control containing your actual link (I guess it has to be the DayView reference against which you would call the FindControl).
However, there is another way to achieve what you need which I suggest you to investigate. Just define the OnInit handler for the actual link itself:
<asp:HyperLink ID="CalendarViewLink" runat="server" OnInit="OnViewLinkInit" Text="View" />
then in codebehind you can set the NavigateUrl for your link using s parameter:
protected void OnViewLinkInit(object sender, EventArgs e)
{
HyperLink link = (HyperLink)sender;
link.NavigateUrl = "url";
}
The above OnInit handler will be called as many times as many links will be displayed.
I have a dropdownlist inside a template column on a obout grid. Currently i am populating the dropdownlist on page load with a sqldatasource. However, i now have to load the dropdownlist dependent on the value of a certain column. For example: If status = 1, i populate the dropdownlist with a list of available options that pertain to status 1.
<obout:Column ID="colStatus" DataField="wf_status_id" Align="center" HeaderText="Status" HeaderAlign="center" Width="130px" Wrap="true" runat="server" AllowGroupBy="true" AllowFilter="true">
<TemplateSettings EditTemplateId="tmpStatusIDEdit" TemplateId="tmpStatusID" />
</obout:Column>
<obout:GridTemplate runat="server" ID="tmpStatusID" >
<Template>
<%# Container.DataItem["Status"]%>
</Template>
</obout:GridTemplate>
<obout:GridTemplate runat="server" ID="tmpStatusIDEdit" ControlID="ddlStatus" ControlPropertyName="value">
<Template>
<obout:OboutDropDownList runat="server" ID="ddlStatus" Width="100%" Height="200" MenuWidth="215" DataSourceID="sdsStatus" DataTextField="wf_status_text" DataValueField="wf_status_id" />
</Template>
</obout:GridTemplate>
public void OnGridRowDataBound(object sender, Obout.Grid.GridRowEventArgs e)
{
if (e.Row.RowType == Obout.Grid.GridRowType.DataRow)
{
DropDownList ddlStatus = new DropDownList();
ddlStatus = (DropDownList)e.Row.FindControl("ddlStatus");
//LOAD DROP DOWN HERE//
}
}
When i attempt to execute this code, it shows that ddlStatus is null everytime. I have a tried a multitude of ways to get this and for some reason cannot seem to get it. Perhaps aother set of eyes or other ideas could help me out. Please let me know what it is i am doing wrong. Thank you ahead of time
UPDATE:DATABOUND EVENT CODE
<obout:OboutDropDownList runat="server" ID="ddlStatus" Width="100%" Height="200" MenuWidth="215" OnDataBinding="ddlStatus_DataBinding" DataSourceID="sdsStatus" DataTextField="wf_status_text" DataValueField="wf_status_id" />
protected void ddlStatus_DataBinding(object sender, EventArgs e)
{
Obout.Interface.OboutDropDownList ddl = (Obout.Interface.OboutDropDownList)(sender);
string statusID = Eval("wf_status_id").ToString();
}
I added the DataSource because i do not see another way to have the databinding event triggered.
I don't really know anything about obout controls but I have to assume they act very similar to the asp.net controls and have just been extended. With that assumption in mind, I will try and answer your question.
Your RowDataBound event has a few coding issues... for example, I am not sure why you are defining a new DropDownList and then trying to overwrite it with the next line. Also it sounds like the next line is returning null anyways.
First off I suggest not using the DataBound event at the row level. Use the control's DataBinding event as it will localize your code a lot better because you can trigger off the specific control's DataBinding and therefore not have to search for it. If your code changes (markup or codebehind) it is also a lot easier to change as it will not affect other things and there is less room for introducing bugs.
So I would make the following changes to address this:
Change your DropDownList definition to implement DataBinding:
<obout:OboutDropDownList runat="server" ID="ddlStatus" Width="100%" Height="200"
MenuWidth="215" OnDataBinding="ddlStatus_DataBinding" />
Then implement the OnDataBinding event (get rid of your DataBound event if you weren't using it for anything else):
protected void ddlStatus_DataBinding(object sender, System.EventArgs e)
{
// This will point to ddlStatus on the current row that is DataBinding so you
// don't have to search for it.
OboutDropDownList ddl = (OboutDropDownList)(sender);
// Now you can fill the DropDownList and set the default value how ever you like
...
}
You can also see this other question I answered a long time ago to see if it helps as it is doing the same thing but with a Repeater but it is pretty much the same thing as a grid:
Populating DropDownList inside Repeater not working
EDIT: Changed the code to use OboutDropDownList in the DataBinding.
you can find plenty of samples on obout knowledge base and examples. These should help you out: http://www.obout.com/combobox/aspnet_integration_grid.aspx, http://www.obout.com/grid/aspnet_ajax_cascading_comboboxes.aspx
(they refer to comboBox, but you can easily adapt them do a ddl)
I'm trying to add a button to the webpage, from the code behind. I have a single empty div on my main page that visible on and off, when needed. However the content I wish to create dynamically as the div content can change dependent on conditions.
I have realised that within my ASP Control I use a / (backslash) which cancels out my HTML. The problem I now have is understanding how I can get around this with code, is there a way to add ASP Controls to the web page? I am open to suggestions outside of the InnerHtml.
I'm creating my Button like so (in my Code Behind):
string buttonout = string.Format("<asp:Button ID=\"helpButton_0\" CommandArgument=\"0\" CssClass=\"HelpButton\" runat=\"server\" Text=\"?\"/>");
innercontent[0] = string.Format("<table><tr><td>Lead Passenger Information</td></tr><tr><td>Here by deafaul we used your detaisl from your profile, if you're not the lead passenger (As in you're booking for someone else) then please change details.</td></tr><tr><td>{0}</td></tr></table>"+ buttonout);
As Said above, The reason this doesn't work is because of InnerHtml hating backslashes, I think.
I do have a solution to this; and that's by adding more divs to the page.
<div id="HelpBoxDiv" runat="server" Visible="false">
<div id="HelpBoxDiv_Top" runat="server" Visible="true">
</div>
<div id="HelpBoxDiv_Bottom" runat="server" Visible="true">
<asp:Button ID="button_HelpBox_false" runat="server" />
</div>
</div>
I would then add my Innerhtml to the _Top Div, instead of the HelpBoxDiv which I am currently doing now. However this solution doesn't teach me anything.
I am hesitant to ask questions here, as I know a lot of question have been asked and I am sure this one has before, but I didn't find a solution. Any help is much appreciated.
Thank you.
I have realised that within my ASP Control I use a / (backslash) which
cancels out my HTML. The problem I now have is understanding how I can
get around this with code, is there a way to add ASP Controls to the
web page? I am open to suggestions outside of the InnerHtml.
You cannot add ASP.Net server control like a literal string.
Instead, you want to add the dynamic server control to the following approach -
ASPX
<asp:PlaceHolder runat="server" ID="PlaceHolder1"></asp:PlaceHolder>
Code Behind
protected void Page_Init(object sender, EventArgs e)
{
var button = new Button
{
ID = "helpButton_0",
CommandArgument = "0",
CssClass = "HelpButton",
Text = "?"
};
button.Command += button_Command;
PlaceHolder1.Controls.Add(button);
}
private void button_Command(object sender, CommandEventArgs e)
{
// Handle dynamic button's command event.
}
For some reason, this code isn't working:
Code-Behind
protected void btnNote_Clicked(object sender, EventArgs e)
{
DevExpress.Web.ASPxPopupControl.ASPxPopupControl notePopup = (DevExpress.Web.ASPxPopupControl.ASPxPopupControl)Master.FindControl("TaskBar").FindControl("pcNote").FindControl("notePopup");
notePopup.ShowOnPageLoad = true;
}
.aspx (event)
<asp:Button ID="btnNote" runat="server" Text="Add Note" OnClick="btnNote_Clicked" />
I need to write a function that takes this popup control ('notePopup') and displays it, and I believe this is supposed to work, but for some reason, once the page is reloaded, there is no popup.
#Jordan, try to add the ASPxPopupControl inside the same MS UpdatePanel. In this case, I believe everything will work properly. What are your results?
I figured it out myself, although what I'm doing now I'm 100% sure I already did, and I'm not sure what else could have changed that affected my results since then, so I'm closing the question.
i have the following problem:
i work in web application and only today. any control i put on the page, when trying to access it from behind code. it doesn't appear at all. what are the probabilities and reasons for this problem.
note:
i work from a thin client. they make some maintenance on their server today. and after that i find this problem.
the previous controls on my page can be accessed normally with out any problems.
See if the controls have an ID this might sound stupid but perhaps yesterday someone
created the view with a snippet label *tab *tab and forgot to add an id
Below result of label *tab *tab ..
<asp:Label Text="text" runat="server" />
Should be
<asp:Label Text="text" ID="lblInfo" runat="server" />
Else check the attributes of the page / controls / codebehindfile
make sure the CodeBehindFile attributes are set correctly
see if run at server attribute is properly set on new controls