שאלה ב ASP.NET

The Birdy

New member
שאלה ב ASP.NET

יש לי דף שיש בו USER CONTROL עכשיו בדף הראשי יש לי DATAGRID עשיתי עדכון של ה DATAGRID וזה עדכן את ה DATABASE הכל יפה. רק באותו דף שחוזר אחרי העדכון ה USER CONTROL מציג את הנתונים הישנים כנראה מכוון שלקיחת הנתונים מה DB ב USER CONTROL נעשית לפני עדכון הנתונים של ה DATAGRID איך אני פותר את הבעיה הזו? נראה לי בעיה דיי פשוטה רק שאני לא ממש מצליח להסתדר איתה תודה אנשים וגם נשים...
 

gilad g

New member
זה בגלל ה-ViewState

תאמר לקונטרול שלך לרפרש את עצמו, ולקחת את הנתונים מחדש מה-DB.
 

The Birdy

New member
הקונטרול לוקח כל פעם את הנתונים

הקונטרול לוקח כל פעם את הנתונים מה DB.
 

The Birdy

New member
או ליתר דיוק איך אני אומר לו להתרענ

או ליתר דיוק איך אני אומר לו להתרענן?
 

gilad g

New member
תראה קצת קוד.

אי אפשר לעבוד "על עיוור"
 

The Birdy

New member
אנשים אוהבים לראות קוד...

או קי נראה קוד אם זה יעזור..
ממש בקיצור..
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("DSN1")) Dim myCommand As SqlCommand = New SqlCommand("ShoppingCartUpdateItem", myConnection) ' Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure ' Add Parameters to SPROC Dim parameterProductID As SqlParameter = New SqlParameter("@ProductID", SqlDbType.Int, 4) parameterProductID.Value = productID myCommand.Parameters.Add(parameterProductID) Dim parameterCartID As SqlParameter = New SqlParameter("@CartID", SqlDbType.NVarChar, 50) parameterCartID.Value = cartID myCommand.Parameters.Add(parameterCartID) Dim parameterQuantity As SqlParameter = New SqlParameter("@Quantity", SqlDbType.TinyInt, 1) parameterQuantity.Value = quantity myCommand.Parameters.Add(parameterQuantity) ' Open the connection and execute the Command myConnection.Open() myCommand.ExecuteNonQuery() myConnection.Close()​
עדכון כמות המוצר עכשיו ב USER CONTROL אחר אני מבקש את הסכום הכללי של הקניה... הנה הקוד
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("DSN1")) Dim myCommand As SqlCommand = New SqlCommand("ShoppingCartTotal", myConnection) ' Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure ' Add Parameters to SPROC Dim parameterCartID As SqlParameter = New SqlParameter("@cartID", SqlDbType.NVarChar, 50) parameterCartID.Value = cartID myCommand.Parameters.Add(parameterCartID) Dim parameterTariffID As SqlParameter = New SqlParameter("@tariffID", SqlDbType.SmallInt, 50) parameterTariffID.Value = ConfigurationSettings.AppSettings("TariffID") myCommand.Parameters.Add(parameterTariffID) Dim parameterTotalCost As SqlParameter = New SqlParameter("@totalCost", SqlDbType.Money, 8) parameterTotalCost.Direction = ParameterDirection.Output myCommand.Parameters.Add(parameterTotalCost) ' Open the connection and execute the Command myConnection.Open() myCommand.ExecuteNonQuery() myConnection.Close() ' Return the Total If parameterTotalCost.Value.ToString() <> "" Then Return CType(parameterTotalCost.Value, Decimal) Else Return 0 End If​
נפלא אה...
 

The Birdy

New member
מממ...

אם אני ארשום פה את כל הקוד אז.. (אין מקום) השאלה היא כללית אפשר גם בלי קוד.. אבל תודה בכל אופן..
 

gilad g

New member
אתה אומר ל-user conrol

פשוט למשוך את הנתונים מה-DB מחדש... בעצם.. באיזה אירוע של ה-user control אתה אומר לו לשלוף את הנתונים מ-DB
 

gilad g

New member
המממ

נסה לומר לו לעשות את זה ב-PreRender.... או בכל אירוע שמתרחש אחרי Page_Load...
 

nattygur

New member
היי, זה מאוד קשה בלי קוד אבל..

אם הבנתי נכון יש לך מסך שעליו יש גריד ו UserControl. הגריד וה UserControl מראים אותו סט נתונים מבסיס נתונים (אותה טבלה). אתה עושה שינוי בגריד אבל לא רואה את השינויים ב UserControl. כנראה שהבעיה היא שה UserControl לא מעדכן את הנתונים מבסיס הנתונים אלה משתמש ב ViewState. בדרך כלל נהוג להגן מילוי נתונים ע"י שימוש ב IsPostBack בכדי למנוע מילוי נתונים ב PostBack (הם קיימים ב ViewState). תבדוק אם זה המצב ב UserControl שלך. עוד אופציה היא שה UserControl משתמש ב Outputchache ולכן הנתונים לא מתעדכנים (הם נלקחים מה Cache). אבל הכל השערות ....
 

gilad g

New member
...ועוד השערה

יכול להיות שב-user control, הטעינה מהמסד נתונים היא ב-OnLoad שלו, ואילו השמירה למסד הנתונים היא ב-OnClick של איזה כפתור. אירועים הם אחרי OnLoad, ולכן יכול להיות שה-onload מתבצע לפני ה-onclick, הווי אומר הקריאה ממסד הנתונים נעשית לפני הכתיבה אליו.
 

The Birdy

New member
זאת ההשערה הנכונה וגם רשמתי את זה..

זאת ההשערה הנכונה וגם רשמתי את זה.. (אני מאמין) קריאת הנתונים מתבעצת לפני הכנסת הנתונים ולכן מוצגים לי נתונים ישנים מה לעשות? איך קוראים אז לפונקציה שנמצאת בתוך USER CONTROL מהדף הראשי זה כנראה יפתור לי את הבעיה.. אני מקווה.. תודה
 

raikyng

New member
בכדי לקרוא לפונקציה מהקלאס הראשי

תגדיר משתנה של ה CLASS )WEBFORM( ותוכל לפנות לכל המתודות הציבוריות שלו
 
למעלה