Object dropdown missing "Server Objects & Events" - c#

In VS2008 source view, the left side object dropdown is missing "Server Objects & Events", and "Server Code". I would like to know how to enable these to be visible.
The controls on the page do contain runat="server".

Those items only appear if you are using a single-page model for your code (i.e., html and code are both in the aspx page with no code-behind). If you are using a code-behind file, then you will not get those options while looking at the page's source view.
See the yellow box part way down this page in MSDN.

when you create a new asp page clear the check box for place code in separate file.This ensures that the IDE puts all code within .aspx file .
after do that...
go to :
Tools > options > Text editor >All languages >General >>>> tick the navigation bar check box
.

Related

Double Clicking Asp button in Designer mode creates function in unwanted aspx.cs fle

On double clicking the asp:Button in Design mode, a button click function is generated in .aspx.cs file of some other .aspx file. How do I make it such that on double clicking the button, it opens in the same page's cs file?
Note: I am using Visual Studio 2022 (free)
Example :-
I have 2 web pages:-
web.aspx (web.aspx.cs)
web1.aspx (web1.aspx.cs)
Now if I double click on a button in design mode of web.aspx file, then a button_click function is being created in web1.aspx.cs file, but Onclick event is being added to the button in web.aspx.
How do I make it such that on double clicking, the function is created in web.aspx.cs itself ?
Most likly the issue is that new page was NOT created by Visual Studio, but you made a copy of the page.
Check the topmost line in the markup page.
so, say the page is called MyUpLoadTest2.aspx
(the "2" kind of gives away the fact that I made a copy of this page).
Note this part:
<%# Page Language="C#" AutoEventWireup="true"
CodeBehind="MyUpLoadTest2.aspx.cs"
Inherits="CSharpWebApp.MyUpLoadTest2" %>
Check both codeBehind, and make sure it matches the page name (MyUpLoadTest2).
And also check the Inherits in above - again make sure it matches the code behind.
Also, view the code page, and make sure the class name for the page matches the page name.
eg this:
public partial class MyUpLoadTest2 : System.Web.UI.Page
So, make sure all 3 match.
if the page directive in the markup does not match the correct name, or is pointing to a different code file, then you see the effect you note - the code will be created in the wrong page.
Another issue/thing to avoid?
Don't name the page the SAME as any class you have - including built in ones, as that can say mess things up.
So, for example, you might try to call a page GridView, but there is a gridview control, and thus you don't want your page to have the same name, since then the code behind page class will wind up with the same name as that existing class (built in ones, or even control names).
So, check your page directive.
In many cases, you are better off to create a new blank page, and then cut + paste in the markup between the "form" tags, and leave the rest of the page alone.

enable or disable side menu in global master file c# asp.net website

I'm writing a website in Visual Studio Web Developer 2010 (Express edition). I have created a Master file which my content is styled with.
I want to put a right hand menu in my master file, but from the actual website pages, I want to say whether it should show particular menu items. For example, the home page would have a certain set of menu items on the right where as the contact page might have another set.
Should I set it up so that the master file handles true or false as to whether to show certain menu items (default all to false)... or should I handle this from the content pages? ie: call menu functions to draw from there?
You can add a master page declaration to the page, so that you can access it programmatically like so:
<%# MasterType virtualPath="~/MasterPage.master"%>
Put that right under the Page tag on the page you want to enable or disable access from.
Then, in your code behind, you can access the master page methods, one of which can be a method to enable or disable that side menu.
Something like:
Master.MyEnableMenuMethod();
Additionally, you can add that Master Page declaration dynamically, like so:
void Page_PreInit(Object sender, EventArgs e)
{
this.MasterPageFile = "~/MasterPage.master";
}
See http://msdn.microsoft.com/en-us/library/c8y19k6h(v=vs.85).aspx for more.
The way I've done this sort of thing is by putting some code withing the menu markup as so:
<% if(!HttpContext.Request.Path.Contains("Contact.aspx")) { %>
<li> Contacts</li>
<%}%}>
And so on...

Controls in a telerik control not accessible from .cs file

I am trying to use this solution to access items inside a telerik menu item:
ascx code:
<asp:Label ID="DivLeave" runat="server"></asp:Label>
In the ascx.cs file I run this code to disable the asp label
RadMenuItem expenses = RadMenu1.FindItemByText("Expenses");
Label DivLeave = (Label)expenses.FindControl("DivLeave");
DivLeave.Visible = false;
but I get this error when I try to run the code:
{"Object reference not set to an instance of an object."}
Can anyone tell me how to fix this problem. I really need to run this server side as code surrounding the above code does some work server side and it will all fit in neatly...
Kind regards
This is because the name of your label is not "DivLeave" when the HTML for your form is rendered. Since it is inside a user control it will be a combination of the user control name on the page and then "DivLeave". You should be able to see the name by looking at the code behind. Also why can't you just reference DivLeave.Visible without using the FindControl? Its an ASP.NET control with the runat server attribute so it should be available to you.
Can you do a quickwatch for 'expenses' object in Visual Studio and see if 'DivLeave' is available? It may so happen that:
The label control is available but at a different level in the object.
The label control itself is not getting added to the parent 'expenses'.
Also, it would be a good idea to do a null check for expenses and DivLeave objects before accessing them.

Need html code of GridView within C# code

I am having an aspx page with a user control in it. The usercontrol contains the GridView. At some place within this usercontrol i need html code of GridView.
Can anybody provide help on how i can get html code of GridView.
Thanks for sharing your time.
The best source is to put a gridview into an aspx page and render it on the browser. On the browser, you can just right-click and View the source. You can copy paste and change accordingly.
What do you mean html code? I'm assuming you don't want to view the HTML code via your browser --> View Source (or alternatively click on the control and view source), but do some sort of extraction/editing in HTML via your code in C#? Is that correct? If so you might be able to use JQuery - but it dpeends on your requirements.
EDIT: You can also try Firebug for Firefox since that can show you client side as code that's coming in from JavaScript, CSS, etc.
i hope i am not too late for answering your question, but your problem can be solved by overriding VerifyRenderingInServerForm
you just got to paste the following code in code behind
public override void VerifyRenderingInServerForm(Control control)
{
}

Navigating between DotNetNuke module controls using EditURL() or NavigateURL()

OK I'm new to DotNetNuke and need to write a simple module in DNN that will display an article for everyone, and allow the admin to edit the article/add a new one.
I have a test page that contains a DNN module with one module definition and two controls in that definition. The default control shows the article based on an articleID field in the querystring. You then click a button that is supposed to load the edit control and pass the articleID in the query string.
If I use EditURL() in the onClick the edit control is loaded with the correct articleID, but using the admin skin. If I use Globals.NavigateURL() then the correct skin is shown but my edit control isn't loading in the page.
Any clue as to how to what I'm doing wrong or how to get the edit control loading with the correct skin?
My two methods of switching to the edit control (in my button click event) are listed below:
string newURL = this.EditUrl("articleID", Request.QueryString["articleID"], "EditArticle");
Response.Redirect(newURL);
and
string newURL = Globals.NavigateURL(this.TabId, "EditArticle","articleID="+Request.QueryString["articleID"]);
Response.Redirect(newURL);
Actually you are doing this correctly - the editurl in DNN does load the Admin skin - usually this skin is based on someone administering content so it strips out all other modules and shows the 'basics'. Right or wrong this is what it does.
If you dont want to to do that you could provide a switch in the querystring and show a seperate panel or do a multiview control and show different views based on the switch in the query string.
There are a few other approaches like changing the content area to editing text area with ajax or using popup modal style windows.

Categories

Resources