.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Declaration of a Variable in a webform

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :ASP.Net
Hi All, Please review my code, i've removed the most part of the code which is not relevant to this: namespace MyQuiz { public partial class QuizPage : System.Web.UI.Page { protected int[] idquestion = new int[totalQuestions]; public QuizPage() { Page.Init += new System.EventHandler(Page_Init); } private void ReadQuestionsIntoTable() { IEnumerable questions = SelectRows("Select * From Questions WHERE QuizID='48'"); //Ashiq Code int a = 0; foreach (DataRowView question in questions) { a++; } totalQuestions = a; foreach (DataRowView question in questions) { idquestion = new int[totalQuestions]; idquestion[NumberOfQuestions] = Convert.ToInt16(question["QuestionID"].ToString()); } } protected void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { ReadQuestionsIntoTable(); } else { bool AreAllAnswered = CalculateScore(r);

View Complete Post

More Related Resource Links

Function and Variable declaration with out an 'As' clause


I get a message - "Function without an 'As' clause" for HMAC_MD5 and "Variable declaration without an 'As' clause" for Key and Value.  But the code works.  But the messages still exists.  Is there a way to fix this to avoid the messages?

Function HMAC_MD5(ByVal Key, ByVal Value)


Initializing more than one variable at declaration


Guys, i am looking for this using google search but without success yet...

How can I do this:

private string a, b, c, d ,e = "";

I want ALL the variables to start with "" but this is not what i get...  so i am doing this until the answer does not come:

private string a,b,c,d,e;

a = b = c = d = e = "";



Global variable declaration



I am using the following code:

    var dbSelect = Database.Open("XXXXXX") ;
    var selectQueryString = "SELECT * FROM XXXX ;
    var data = dbSelect.Query(selectQueryString);
Now If I put the above code in try catch block, then "data" variable is not accessible outside try block. How I can declare "data" variable globally and then can collect result in it in try block?

Sql 2008 Variable declaration


Wondering can we do like below.


SELECT @iSalary = Salary

FROM dbo.udf_Get_Salary(EMP0001)


Instead of doing old conventional way




SELECT @iSalary = Salary

FROM dbo.udf_Get_Salary(EMP0001)


ASP.NET 4.0: WebForm Routing (quick n dirty version)

One of the things we're adding in ASP.NET 4.0 is built-in support for using Routing together with WebForms. Now, I'm totally aware that this is possible to do already and that a number of people have posted ways of doing this with the Web Routing feature which shipped with ASP.NET 3.5 SP1. We're just adding some features to make it easier to do

Local variable scoping in C#

In my previous post, Compiler-generated scopes for local variable declarations, I briefly touched on the issue of multiple meanings applied to the same name. In this post, I'll aim to flush out the compiler's rules with regards to binding names in their local scopes.

Compiler-generated scopes for local variable declarations

I was tasked with understanding and fixing a bug on error reporting with foreach iteration variables the other day, and it got me thinking about local variable scoping rules in C# in general. First, the bug.

Retrieving a variable from a previous page



I'm looking to have a search page where a user will select an item from a listview, then then taken to another page that wil display data based on their original selection.

A user will type in a string and be presented with a list of usernames that are like that string, when they select a user name who's profile they would like to view I would like the page that they're taken to, to be that users profile.

How would I transfer the variable from the search page to the profile page, and when I work on the profile page, how can I access that variable?


Embeb a variable number of videos


I need to provide some alternate content for my non-Flash users.

I have a directory of video files that is scanned using the DirectoryInfo() function, and I want to use the results to embed all files ending in ".mov" in QuickTime players on a web form.

How would you approach this? Right now I am using the count on the array of videos to determine how many times to repeat the embed code.  But this seems inelegant.

Is there a way to have a single QuickTime player.ascx control that gets duplicated according to the number of videos available for display?

How to take value of bound field of grid in a variable or in a textbox.


How to take value of bound field of grid in a variable or in a textbox.

 I m using this code in .aspx page for grid.

<asp:GridView ID="Grd_Mprocess" runat="server" AutoGenerateColumns="False"

                      Width="100%" AllowPaging="True"


                      AllowSorting="True" PageSize="5"  >

                 <RowStyle CssClass="odd" />


<asp:BoundField HeaderText="DOC_TYPE_PK" DataField="DOC_TYPE_PK"  Visible="true" >


  <asp:TemplateField HeaderText="DOC TYPE ID" Visible="true">  &nbs

Hidden variable has no value


I know I have a valid solution, but the js is telling me that the value in the hdnRecordSaved variable has no value!
Even when I specify in my function the following, it still tells me it has no value:
var myTextField = document.getElementById('hdnRecordSaved');

When I put the full value of the variable in (ctl00_ctl00_cphTopCenter_cphCenter_hdnRecordSaved.value), I get the correct contents back ("1"), which I set in my code behind. However, I would prefer to just put the short name in since the masterpages may change, etc. Unfortunately, I know I can get around this with VS2010, but we are using VS2008.

What am I doing wrong with the js naming conventions that can't give me the contents? Here is my below js.

<asp:Panel ID="pnlMapFields" runat="server" ScrollBars="Both" Height="430px">

<telerik:RadTreeView ID="RadTreeView1" runat="server" DataTextField="Description"

DataFieldParentID="MapFieldparentID" DataF

How to retrieve data from SqlDataSource and pass to a variable?


Hi there,

I have a page in my website where there is very little code-behind. I only have two lines of code in Page_Load() and the rest of the code is declarative ASP.NET code. I have a FormView control which uses a SqlDataSource to get some order information. The SqlDataSource calls a stored procedure called usp_GetOrderDetails, here's the code for the SqlDataSource:

    <asp:SqlDataSource ID="sdsFormOrderDetails" runat="server" 
ConnectionString="<%$ ConnectionStrings:ForexDB %>"
ProviderName="<%$ ConnectionStrings:ForexDB.ProviderName %>"
SelectCommand="usp_GetOrderDetails" SelectCommandType="StoredProcedure"
UpdateCommand="usp_UpdateOrder" UpdateCommandType="StoredProcedure"
<asp:ControlParameter Name="orderId" ControlID="grdOrders" PropertyName="SelectedDataKey.Value" />
<asp:ControlParameter Name="orderId" ControlID="frmOrderDetails" PropertyName="SelectedValue" />

VB webform in IronPython asp.net website


Hi, I tried to bring a previously done webform made in vb.net to an IronPython asp.net website with no luck. After seeing it didnt work, I tried to write the simplest codebehind vb.net webform to see if there was a problem with vb.net in an IronPython website and I got the following usual error "be sure that the defined class in this file matchs with the one in the attribute inherits and that it extends the right base page (page or control)" (sorry if the translation isnt the most accurate I get that message in spanish) but if I create a vb.net webform in the same website, with the sourcecode in the same file (with the vb.net code between script runat="server" tags in the same page) I get no problem. Do I have to configure something for both kind of sourcecode languages to run in such way in the same IronPython website, like configuring something in the webconfig file or is there some compatibility issue for doing that which can't be resolved?

I figured out that in some cases I can solve it by creating the app_folder and moving the vb files there, but if these files dont inherit other classes which are in the app_folder

{ End Bracket }: The Digital Declaration of Independence


Bill Hill discusses his Digital Declaration of Independence.

Bill Hill

MSDN Magazine Launch 2008

Object declaration problems


 in the vb code below @ 'Print the Amount and Description to the page by placing them in the Spans'
I'm getting messages that the two variables aren't declared, however it seems to be printing them on the form.  Also, I'm getting the same message for all the variables @ 'Update the fields in the actual form'.  This is Auhtorize.Net sample code.  I can't get the code to work.  The error is that the merchant id is invalid and I think it might be because of the "variable not declared" message mentioned above.  Can someone look at the code and, with their asp/vb hat on, see what change I need to make to clear the declaration issues?  Then I'll see if that helps. 

Also, at 'This is a wrapper for the VB.NET's built-in HMACMD5 functionality', I get a message that I am using a function without an 'As' clause.  How do I fix this?



<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="SIM_Example._Default" %>


Session Variable issues


Hello everyone,

I ran into an issud to day with the follwoing code.  The strPanelOrder session variable is false, however, once it goes into the next if statement and sets the strTrimOrder to True, it changes the strPanelOrder session varialbe to true as well.  Why is this and how to I stop that from happening?

If Session(strPanelOrder) Is "False" Then
                If (strItemNumber.Length() = 10) And (strItemNumber.Substring(0, 2) = "FS" Or strItemNumber.Substring(0, 2) = "FC" Or strItemNumber.Substring(0, 2) = "DS" Or strItemNumber.Substring(0, 2) = "DC") Then
                    Session(strPanelOrder) = "True"
                End If
End If
If Session(strTrimOrder) Is "False" Then
               If (strItemNumber.Substring(4, 1) = "T") And (strItemNumber.Substring(0, 2) <> "AC") And (strItemNumber <> "Length") Then
                    Session(strTrimOrder) = "True"
                End If
End If


Thanks in advance for taking a look at this.



BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its


why do i get

BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

with the code

 below ..thanks


<form id="form1" runat="server">
               <asp:Button ID="Button1" runat="server" Text="Run Access" />
In your code behind:

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend